Function leon::vals

source ·
pub const fn vals<F>(func: F) -> ValuesFn<F>
where F: Fn(&str) -> Option<Cow<'static, str>>,
Expand description

Wraps your function so it implements Values, though it only works if your function returns Cow<'static, str>.

Since regular function pointers cannot return anything other than Cow<'static, str> and closure in Rust currently does not support returning borrows of captured data, supporting anything other than Cow<'static, str> for functions is pointless and would only cause more confusion and compile-time errors.

To return &str owned by the values itself, please create a newtype and implement Values on it manually instead of using this function.

§Example

use leon::{Values, vals};

fn use_values(_values: impl Values) {}

use_values(&vals(|_| Some("hello".into())));