lazy_fn
lazy_static
for functions!
Makes the attributed function "lazy"; it will only be evaluated once and the result will be cached and thus returned as a static reference.
In your Cargo.toml
:
toml
[dependencies]
lazy_fn = "1"
lazy_static = "1"
In your code:
```rust
fn maths() -> i32 { 9 + 10 }
fn hello_world() -> &'static str { "hello, world!" }
fn hello_fmt() -> String { format!("hello, {}!", "world") }
let maths: &'static i32 = maths(); let helloworld: &'static str = helloworld(); let hellofmt: &'static String = hellofmt(); ```