pub trait Provider {
    fn provide<'a>(&'a self, demand: &mut Demand<'a>);
}
🔬This is a nightly-only experimental API. (provide_any #96024)
Expand description

Trait implemented by a type which can dynamically provide values based on type.

Required Methods

🔬This is a nightly-only experimental API. (provide_any #96024)

Data providers should implement this method to provide all values they are able to provide by using demand.

Note that the provide_* methods on Demand have short-circuit semantics: if an earlier method has successfully provided a value, then later methods will not get an opportunity to provide.

Examples

Provides a reference to a field with type String as a &str, and a value of type i32.

use std::any::{Provider, Demand};

impl Provider for SomeConcreteType {
    fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
        demand.provide_ref::<str>(&self.field)
            .provide_value::<i32>(self.num_field);
    }
}
Run

Implementors