Trait ParamMaybeRef

Source
pub trait ParamMaybeRef<T> {
    // Required method
    fn param_maybe_ref(&self) -> Option<&T>;
}
Expand description

Item of type T may have been set in a certain_map slot and returns Option<&T>

When used as a trait bound, ParamMaybeRef<T> ensures that the constrained type implements the param_maybe_ref method, which returns an Option<&T>. This allows the caller to attempt to retrieve a reference to the value of type T from the implementing type, if it has been previously set in a certain_map slot using ParamSet<T>.

The ParamMaybeRef<T> trait does not guarantee that the value has been set in the certain_map slot. Instead, it returns an Option<&T>, which will be Some(&T) if the value has been set in the certain_map slot, and None if the value has not been set.

§Example

fn process_param_maybe_ref<P: ParamMaybeRef<T>, T>(param_provider: &P) {
    if let Some(value_ref) = param_provider.param_maybe_ref() {
        // Use the reference to the value of type T
    }
}

Required Methods§

Implementors§