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",
]
[[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]]
name = "async-trait"
version = "0.1.80"
@ -1219,6 +1230,7 @@ version = "0.35.1"
dependencies = [
"arc-swap",
"askama",
"async-recursion",
"base64 0.22.1",
"brotli",
"build_html",

View File

@ -44,6 +44,7 @@ pretty_env_logger = "0.5.0"
dotenvy = "0.15.7"
rss = "2.0.7"
arc-swap = "1.7.1"
async-recursion = "1.1.1"
[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
/// 429, or if we were unable to decode the value in the `Location` header.
#[cached(size = 1024, time = 600, result = true)]
#[async_recursion::async_recursion]
pub async fn canonical_path(path: String, tries: i8) -> Result<Option<String>, String> {
if tries == 0 {
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);
// Decrement tries and try again
Box::pin(canonical_path(uri, tries - 1)).await
canonical_path(uri, tries - 1).await
}
None => Ok(None),
},