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
- Create an immutable (safe in any case) Meyer’s singleton in the current scope.
- Create an mutable (not safe in multithreading contexts) Meyer’s singleton in the current scope.