[][src]Struct fluent_builder::FluentBuilder

pub struct FluentBuilder<TValue, TStack = DefaultStack, TStorage = DefaultStorage> where
    TStorage: Storage<TValue>, 
{ /* fields omitted */ }

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

The FluentBuilder<T> is effectively a StatefulFluentBuilder<T, ()>.

Methods

impl<TValue, TStack, TStorage> FluentBuilder<TValue, TStack, TStorage> where
    TStorage: Storage<TValue>, 
[src]

pub fn new() -> Self[src]

Create a default FluentBuilder.

impl<TValue, TStack, TStorage> FluentBuilder<TValue, TStack, TStorage> where
    TStorage: Storage<TValue>, 
[src]

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

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.

impl<TValue, TStorage> FluentBuilder<TValue, Stack, TStorage> where
    TStorage: Storage<TValue>, 
[src]

pub fn fluent<TNextMethod>(
    self,
    fluent_method: TNextMethod
) -> FluentBuilder<TValue, Stack, Apply<TValue, TStorage::Method, ByValue<TNextMethod>>> where
    TNextMethod: FnOnce(TValue) -> TValue, 
[src]

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.

pub fn fluent_mut<TNextMethod>(
    self,
    fluent_method: TNextMethod
) -> FluentBuilder<TValue, Stack, Apply<TValue, TStorage::Method, ByRefMut<TNextMethod>>> where
    TNextMethod: FnOnce(&mut TValue), 
[src]

Stack a fluent method on the builder.

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

impl<TValue, TStorage> FluentBuilder<TValue, Override, TStorage> where
    TStorage: Storage<TValue>, 
[src]

pub fn fluent<TNextMethod>(
    self,
    fluent_method: TNextMethod
) -> FluentBuilder<TValue, Override, Apply<TValue, DefaultStorage, ByValue<TNextMethod>>> where
    TNextMethod: FnOnce(TValue) -> TValue + 'static, 
[src]

Create a new StatefulFluentBuilder from the given value.

pub fn fluent_mut<TNextMethod>(
    self,
    fluent_method: TNextMethod
) -> FluentBuilder<TValue, Override, Apply<TValue, DefaultStorage, ByRefMut<TNextMethod>>> where
    TNextMethod: FnOnce(&mut TValue) + 'static, 
[src]

Set the fluent method on the builder.

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

impl<TValue, TStack, TStorage> FluentBuilder<TValue, TStack, TStorage> where
    TStorage: Storage<TValue>, 
[src]

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

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.

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

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 = FluentBuilder::<String, Stack>::new()
    .value("A value".to_owned())
    .fluent_mut(|mut s| s.push_str(" and more"));

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

impl<TValue, TStack, TStorage> FluentBuilder<TValue, TStack, TStorage> where
    TValue: 'static,
    TStorage: Storage<TValue> + 'static, 
[src]

pub fn boxed(self) -> BoxedFluentBuilder<TValue, TStack>[src]

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

impl<TValue, TStack, TStorage> FluentBuilder<TValue, TStack, TStorage> where
    TValue: 'static,
    TStorage: Storage<TValue>,
    TStorage::Method: Send + 'static, 
[src]

pub fn shared(self) -> SharedFluentBuilder<TValue, TStack>[src]

Box a fluent builder so it can be easily shared.

Trait Implementations

impl<TValue, TStack, TStorage> Default for FluentBuilder<TValue, TStack, TStorage> where
    TStorage: Storage<TValue>, 
[src]

Auto Trait Implementations

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

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

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]