Skip to content

Memoization of closure #45

@EdwardRaff

Description

@EdwardRaff

Hi, I'm new to Rust - sorry if this is dumb, but I'm not finding a solution.

I have a function that is passed in and user-controlled, and it must be that way. My code will use that function extensively, and in some cases, will re-call the function with the same arguments many times.

The code would be much cleaner if I could memoize the input function, which would mean memoizing a closure that captures the input function. But this code:

    #[memoize]
    let dist_cached = |a: &usize, b: &usize| -> f32{
        return my_dist(a, b);
    };

Does not work.

Is there a way to do or support this kind of operation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions