maybe_static 0.1.0

Initialize a lazy static with params
Documentation

Maybe static

Initialize in a lazy way a static variable with parameters.

use maybe_static::maybe_static;

pub fn get_ip2(opt: Option<(&str, &str)>) -> Result<&'static String, &'static str> {
    maybe_static!(opt, String, |(addr, port)| format!("{addr}:{port}"))
}

fn main() {
    println!("{}", get_ip2(Some(("hello", "world"))).unwrap());
    println!("{}", get_ip2(None).unwrap());
}

Initially developed around the article in the maybeuninit blog