cached icon indicating copy to clipboard operation
cached copied to clipboard

Document how this should work on floats?

Open EvanCarroll opened this issue 4 years ago • 2 comments

Perhaps it's just a part of the language, but if I want to use

#[cached(time=60)]
async fn get_alerts(config: &cmdline::Config) -> Result<Vec<Alert>, reqwest::Error> {

I would expect that to work as is. The problem I'm having is that Config there contains an f64. That f64 doesn't implement Hash. I think I get how to do this, but perhaps more could be done to help the user in this case? It's kind of a pita to have to write all this code to say NaN = NaN.

EvanCarroll avatar Mar 15 '21 03:03 EvanCarroll

Yeah, floats not implementing hash is just a pain point of the language. An alternative would be to specify a convert that returns a unique value (that does hash) from your config value:

#[cached(..., convert = r#"{ make_config_key(config) }"#)]

jaemk avatar Mar 15 '21 04:03 jaemk

@jaemk what we should if we have float in multiple nested structs as param for cached function?

Request{
     i32,
     &str,
     SomethingElse{
            f32
     }
}

and we have such function: fn CacheableFunc(req: Request)

arxdeus avatar Jan 01 '23 12:01 arxdeus