lazy_fn

Crates.iolazy_fn
lib.rslazy_fn
version1.0.2
sourcesrc
created_at2022-04-27 23:38:24.539868
updated_at2023-03-27 14:52:39.578169
descriptionlazy_static for functions!
homepage
repositoryhttps://github.com/WilliamVenner/lazy_fn
max_upload_size
id576487
size17,271
William (WilliamVenner)

documentation

README

crates.io docs.rs license

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.

Usage

In your Cargo.toml:

[dependencies]
lazy_fn = "1"
lazy_static = "1"

In your code:

#[macro_use] extern crate lazy_fn;

#[lazy_fn]
fn maths() -> i32 {
    9 + 10
}

#[lazy_fn]
fn hello_world() -> &'static str {
    "hello, world!"
}

#[lazy_fn]
fn hello_fmt() -> String {
    format!("hello, {}!", "world")
}

let maths: &'static i32 = maths();
let hello_world: &'static str = hello_world();
let hello_fmt: &'static String = hello_fmt();
Commit count: 5

cargo fmt