jaemk/cached

Cannot use `inner` as parameter name

gitmalong opened this issue · 2 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,
    }
}
omid commented

@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.

omid commented

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