Struct StatefulFluentBuilder

Source
pub struct StatefulFluentBuilder<TSeed, TValue, TStack = DefaultStack, TStorage = DefaultStorage>
where TStorage: Storage<TValue>,
{ /* private fields */ }
Expand description

A stateful structure that can contain a value, or stack mutating methods over one supplied later.

Implementations§

Source§

impl<TSeed, TValue, TStack, TStorage> StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>
where TStorage: Storage<TValue>,

Source

pub fn from_value(value: TValue) -> Self

Create a new StatefulFluentBuilder from the given value.

Source

pub fn from_seed(seed: TSeed) -> Self

Create a new StatefulFluentBuilder from the given seed.

Source

pub fn value(self, value: TValue) -> Self

Set a value on the builder.

This will override any contained state. That means if the builder currently contains fluent methods then those methods will be discarded.

Source§

impl<TSeed, TValue, TStack> StatefulFluentBuilder<TSeed, TValue, TStack, DefaultStorage>

Source

pub fn from_fluent<TNextStorage>( seed: TSeed, fluent_method: TNextStorage, ) -> StatefulFluentBuilder<TSeed, TValue, TStack, Apply<TValue, DefaultStorage, ByValue<TNextStorage>>>
where TNextStorage: FnOnce(TValue) -> TValue,

Create a new StatefulFluentBuilder from the given seed and fluent method.

Source

pub fn from_fluent_mut<TNextStorage>( seed: TSeed, fluent_method: TNextStorage, ) -> StatefulFluentBuilder<TSeed, TValue, TStack, Apply<TValue, DefaultStorage, ByRefMut<TNextStorage>>>
where TNextStorage: FnOnce(&mut TValue),

Create a new StatefulFluentBuilder from the given seed and fluent method.

This method is the same as from_fluent, but mutates the value instead of replacing it.

Source§

impl<TSeed, TValue, TStack> StatefulFluentBuilder<TSeed, TValue, TStack, Shared>

Source

pub fn from_fluent<TNextStorage>( seed: TSeed, fluent_method: TNextStorage, ) -> StatefulFluentBuilder<TSeed, TValue, TStack, Shared>
where TValue: Send + 'static, TSeed: Send + 'static, TNextStorage: FnOnce(TValue) -> TValue + Send + 'static,

Create a new StatefulFluentBuilder from the given seed and fluent method.

Source

pub fn from_fluent_mut<TNextStorage>( seed: TSeed, fluent_method: TNextStorage, ) -> StatefulFluentBuilder<TSeed, TValue, TStack, Shared>
where TValue: Send + 'static, TSeed: Send + 'static, TNextStorage: FnOnce(&mut TValue) + Send + 'static,

Create a new StatefulFluentBuilder from the given seed and fluent method.

This method is the same as from_fluent, but mutates the value instead of replacing it.

Source§

impl<TSeed, TValue, TStack> StatefulFluentBuilder<TSeed, TValue, TStack, Boxed>

Source

pub fn from_fluent<TNextStorage>( seed: TSeed, fluent_method: TNextStorage, ) -> StatefulFluentBuilder<TSeed, TValue, TStack, Boxed>
where TValue: 'static, TSeed: 'static, TNextStorage: FnOnce(TValue) -> TValue + 'static,

Create a new StatefulFluentBuilder from the given seed and fluent method.

Source

pub fn from_fluent_mut<TNextStorage>( seed: TSeed, fluent_method: TNextStorage, ) -> StatefulFluentBuilder<TSeed, TValue, TStack, Boxed>
where TValue: 'static, TSeed: 'static, TNextStorage: FnOnce(&mut TValue) + 'static,

Create a new StatefulFluentBuilder from the given seed and fluent method.

This method is the same as from_fluent, but mutates the value instead of replacing it.

Source§

impl<TSeed, TValue, TStack, TStorage> StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>
where TStorage: Storage<TValue>,

Source

pub fn into_value<TDefault>(self, default_value: TDefault) -> TValue
where TDefault: FnOnce(TSeed) -> TValue + 'static,

Convert the fluent builder into a value.

This method will consume the builder and return a constructed T. This will have the following behaviour if the builder contains:

  • no value or fluent methods, then the default value is constructed.
  • a value, then that value is returned.
  • no value but fluent methods, then the methods are applied over the default value.
  • a value and fluent methods, then the methods are applied over that value.
Source

pub fn try_into_value(self) -> TryIntoValue<TValue, Self>

Attempt to take a value from the builder.

If the builder doesn’t contain a concrete value then it is returned in the Builder variant.

§Examples
let builder = StatefulFluentBuilder::<i32, String, Stack>::from_value("A value".to_owned())
    .fluent(1, |i, s| format!("{} and more {}", s, i));

match builder.try_into_value() {
    TryIntoValue::Value(value) => {
        // The builder has a value that we can use
        assert_eq!("A value and more 1", value);
    },
    TryIntoValue::Builder(builder) => {
        // The builder doesn't have a value but we can still use it
        let value = builder.into_value(|i| i.to_string());
    }
}
Source§

impl<TSeed, TValue, TStorage> StatefulFluentBuilder<TSeed, TValue, Stack, TStorage>
where TStorage: Storage<TValue>,

Source

pub fn fluent<TNextStorage>( self, seed: TSeed, fluent_method: TNextStorage, ) -> StatefulFluentBuilder<TSeed, TValue, Stack, StatefulApply<TSeed, TValue, TStorage::Method, ByValue<TNextStorage>>>
where TNextStorage: FnOnce(TSeed, TValue) -> TValue,

Stack a fluent method on the builder.

This will have the following behaviour depending on the current state of the builder if there is:

  • no previous value, add the fluent method. This will be applied to a later-supplied default value.
  • a previous value, add the fluent method and retain that previous value.
  • a previous fluent method, stack this method on top and retain any previous value.
Source

pub fn fluent_mut<TNextStorage>( self, seed: TSeed, fluent_method: TNextStorage, ) -> StatefulFluentBuilder<TSeed, TValue, Stack, StatefulApply<TSeed, TValue, TStorage::Method, ByRefMut<TNextStorage>>>
where TNextStorage: FnOnce(TSeed, &mut TValue),

Stack a fluent method on the builder.

This method behaves the same as fluent, but mutates the value instead of replacing it.

Source§

impl<TSeed, TValue, TStorage> StatefulFluentBuilder<TSeed, TValue, Override, TStorage>
where TStorage: Storage<TValue>,

Source

pub fn fluent<TNextStorage>( self, seed: TSeed, fluent_method: TNextStorage, ) -> StatefulFluentBuilder<TSeed, TValue, Override, Apply<TValue, DefaultStorage, ByValue<TNextStorage>>>
where TNextStorage: FnOnce(TValue) -> TValue + 'static,

Set the fluent method on the builder.

This will have the following behaviour depending on the current state of the builder if there is:

  • no previous value, add the fluent method. This will be applied to a later-supplied default value.
  • a previous value, add the fluent method and remove that previous value.
  • a previous fluent method, that method will be replaced with the given one.
Source

pub fn fluent_mut<TNextStorage>( self, seed: TSeed, fluent_method: TNextStorage, ) -> StatefulFluentBuilder<TSeed, TValue, Override, Apply<TValue, DefaultStorage, ByRefMut<TNextStorage>>>
where TNextStorage: FnOnce(&mut TValue) + 'static,

Set the fluent method on the builder.

This method behaves the same as fluent, but mutates the value instead of replacing it.

Source§

impl<TSeed, TValue, TStack, TStorage> StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>
where TSeed: 'static, TStorage: Storage<TValue>, TStorage::Method: 'static,

Source

pub fn boxed(self) -> BoxedStatefulFluentBuilder<TSeed, TValue, TStack>

Box a fluent builder so it can be easily captured as a field without generics.

Source§

impl<TSeed, TValue, TStack, TStorage> StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>
where TSeed: 'static, TStorage: Storage<TValue>, TStorage::Method: Send + 'static,

Source

pub fn shared(self) -> SharedStatefulFluentBuilder<TSeed, TValue, TStack>

Box a fluent builder so it can be easily shared.

Auto Trait Implementations§

§

impl<TSeed, TValue, TStack, TStorage> Freeze for StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>
where TValue: Freeze, TSeed: Freeze, <TStorage as Storage<TValue>>::Method: Freeze,

§

impl<TSeed, TValue, TStack, TStorage> RefUnwindSafe for StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>
where TStack: RefUnwindSafe, TValue: RefUnwindSafe, TSeed: RefUnwindSafe, <TStorage as Storage<TValue>>::Method: RefUnwindSafe,

§

impl<TSeed, TValue, TStack, TStorage> Send for StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>
where TStack: Send, TValue: Send, TSeed: Send, <TStorage as Storage<TValue>>::Method: Send,

§

impl<TSeed, TValue, TStack, TStorage> Sync for StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>
where TStack: Sync, TValue: Sync, TSeed: Sync, <TStorage as Storage<TValue>>::Method: Sync,

§

impl<TSeed, TValue, TStack, TStorage> Unpin for StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>
where TStack: Unpin, TValue: Unpin, TSeed: Unpin, <TStorage as Storage<TValue>>::Method: Unpin,

§

impl<TSeed, TValue, TStack, TStorage> UnwindSafe for StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>
where TStack: UnwindSafe, TValue: UnwindSafe, TSeed: UnwindSafe, <TStorage as Storage<TValue>>::Method: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.