Crate maybe_static

Source
Expand description
use anyhow::Result;
pub fn get_ip(opt: Option<(&str, &str)>) -> Result<&'static String> {
   maybe_static!(opt, String, |(addr, port)| format!("{addr}:{port}"))
}

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

Macros§

maybe_static
Create an immutable (safe in any case) Meyer’s singleton in the current scope.
maybe_static_unsafe
Create an mutable (not safe in multithreading contexts) Meyer’s singleton in the current scope.