Trait Provider

Source
pub trait Provider<T>:
    Send
    + Sync
    + Buildable
where T: Clone + Send + Sync,
{ // Required method fn try_get(&self) -> Option<T>; // Provided methods fn missing_message(&self) -> String { ... } fn get(&self) -> T { ... } fn fallible_get(&self) -> Result<T, ProviderError> { ... } }
Expand description

The provider trait represents an object that can continuously produce a value. Provider values can be chained together using the ProviderExt trait.

For convenience, several types from the default library implement this trait.

  • for<T> Option<T> : Provider<T>
  • for<F, T> F : Provider<T> where F : Fn() -> T

Required Methods§

Source

fn try_get(&self) -> Option<T>

Try to get a value from the provider.

Will return Some(v) if value v is available, otherwise None is returned.

§Example
use assemble_core::provider;
let prop = provider!(|| 10);
assert_eq!(prop.try_get(), Some(10));

// options implement provider
let prop = Option::<usize>::None;
assert_eq!(prop.try_get(), None);

Provided Methods§

Source

fn missing_message(&self) -> String

The missing message for this provider

Source

fn get(&self) -> T

Get a value from the provider.

§Panic

This method will panic if there is no value available.

§Example
use assemble_core::provider;
let prop = provider!(|| 10);
assert_eq!(prop.get(), 10);
Source

fn fallible_get(&self) -> Result<T, ProviderError>

Tries to get a value from this provider, returning an error if not available.

The error’s message is usually specified by the missing_message() method.

§Example
use assemble_core::lazy_evaluation::Prop;
use assemble_core::provider;

let provider = provider!(|| 3_i32);
assert!(matches!(provider.fallible_get(), Ok(3)));
let mut prop = Prop::<i32>::new(Id::from("test"));
assert!(matches!(prop.fallible_get(), Err(_)));
prop.set_with(provider).unwrap();
assert!(matches!(prop.fallible_get(), Ok(3)));

Implementations on Foreign Types§

Source§

impl<T> Provider<T> for Option<T>
where T: Send + Sync + Clone + Debug,

Source§

fn try_get(&self) -> Option<T>

Source§

impl<T, F> Provider<T> for Lazy<T, F>
where T: Send + Sync + Clone + Debug, F: Send + FnOnce() -> T,

Source§

fn try_get(&self) -> Option<T>

Implementors§

Source§

impl Provider<FileSet> for FileSet

Source§

impl Provider<FileSet> for Configuration

Source§

impl<T> Provider<Vec<T>> for VecProp<T>
where T: 'static + Send + Sync + Clone,

Source§

impl<T> Provider<PathBuf> for TaskHandle<T>

Source§

impl<T> Provider<T> for AnonymousProvider<T>
where T: Clone + Send + Sync,

Source§

impl<T> Provider<T> for Prop<T>
where T: 'static + Send + Sync + Clone + Debug,

Source§

impl<T, B, R, F> Provider<R> for Zip<T, B, R, F>
where T: Send + Sync + Clone, B: Send + Sync + Clone, R: Send + Sync + Clone, F: Fn(T, B) -> R + Send + Sync,

Source§

impl<T, E> Provider<T> for Result<T, E>
where T: Send + Sync + Clone + Debug, E: Send + Sync + Debug,

Source§

impl<T, F, R> Provider<R> for TaskProvider<T, R, F>
where T: Task + Send + Sync + Debug + 'static, F: Fn(&Executable<T>) -> R + Send + Sync, R: Clone + Send + Sync,

Source§

impl<T, R> Provider<T> for FnProvider<T, R>
where R: Into<Option<T>>, T: Send + Sync + Clone,

Source§

impl<T, R, F, P> Provider<R> for Map<T, R, F, P>
where T: Send + Sync + Clone, R: Send + Sync + Clone, F: Fn(T) -> R + Send + Sync, P: Provider<T>,

Source§

impl<T, R, PT, PR, F> Provider<R> for FlatMap<T, R, PT, PR, F>
where T: Send + Sync + Clone, R: Send + Sync + Clone, PT: Provider<T>, PR: Provider<R>, F: Fn(T) -> PR + Send + Sync,