jaemk / cached

Rust cache structures and easy function memoization

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot use `inner` as parameter name

gitmalong opened this issue · comments

#[cached(
    key = "String",
    convert = r#"{ String::from(symbol) }"#,
    type = "SizedCache<String, Option<String>>",
    create = "{ SizedCache::with_size(10000) }",
)]
fn find(inner: &MyService, symbol: &str) -> Option<String> {
    match inner.find(symbol) {
        Ok(s) => Some(s.address),
        Err(_) => None,
    }
}

fails with

mismatched types
expected reference `&mycrate::provider::service::MyService`
     found fn item `for<'a, 'b> fn(&'a mycrate::provider::service::MyService, &'b str) -> std::option::Option<std::string::String> {sigstore::export::find::inner}`

while the following works

#[cached(
    key = "String",
    convert = r#"{ String::from(symbol) }"#,
    type = "SizedCache<String, Option<String>>",
    create = "{ SizedCache::with_size(10000) }",
)]
fn find(s: &MyService, symbol: &str) -> Option<String> {
    match s.find(symbol) {
        Ok(s) => Some(s.address),
        Err(_) => None,
    }
}

@gitmalong, at the moment, inner is a reserved keyword by the cached lib.
For now, just rename your variable name to something else.

Anyway, this PR will remove this issue and make it harder to have a similar name.

@gitmalong it should be solved, could you please check it and if so close the ticket?