fix(client): use async_recursion crate

This commit is contained in:
Matthew Esposito 2024-09-21 15:44:27 -04:00
parent 69c7a69afd
commit b54620b5aa
3 changed files with 15 additions and 1 deletions

12
Cargo.lock generated
View File

@ -116,6 +116,17 @@ dependencies = [
"nom", "nom",
] ]
[[package]]
name = "async-recursion"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.68",
]
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.80" version = "0.1.80"
@ -1219,6 +1230,7 @@ version = "0.35.1"
dependencies = [ dependencies = [
"arc-swap", "arc-swap",
"askama", "askama",
"async-recursion",
"base64 0.22.1", "base64 0.22.1",
"brotli", "brotli",
"build_html", "build_html",

View File

@ -44,6 +44,7 @@ pretty_env_logger = "0.5.0"
dotenvy = "0.15.7" dotenvy = "0.15.7"
rss = "2.0.7" rss = "2.0.7"
arc-swap = "1.7.1" arc-swap = "1.7.1"
async-recursion = "1.1.1"
[dev-dependencies] [dev-dependencies]

View File

@ -64,6 +64,7 @@ static URL_PAIRS: [(&str, &str); 2] = [
/// `Location` header. An `Err(String)` is returned if Reddit responds with a /// `Location` header. An `Err(String)` is returned if Reddit responds with a
/// 429, or if we were unable to decode the value in the `Location` header. /// 429, or if we were unable to decode the value in the `Location` header.
#[cached(size = 1024, time = 600, result = true)] #[cached(size = 1024, time = 600, result = true)]
#[async_recursion::async_recursion]
pub async fn canonical_path(path: String, tries: i8) -> Result<Option<String>, String> { pub async fn canonical_path(path: String, tries: i8) -> Result<Option<String>, String> {
if tries == 0 { if tries == 0 {
return Ok(None); return Ok(None);
@ -113,7 +114,7 @@ pub async fn canonical_path(path: String, tries: i8) -> Result<Option<String>, S
let uri = format_url(stripped_uri); let uri = format_url(stripped_uri);
// Decrement tries and try again // Decrement tries and try again
Box::pin(canonical_path(uri, tries - 1)).await canonical_path(uri, tries - 1).await
} }
None => Ok(None), None => Ok(None),
}, },