Struct fluent_builder::FluentBuilder [] [src]

pub struct FluentBuilder<TValue, TStack = Override, TFluent = BoxedFluent<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> FluentBuilder<TValue, TStack, BoxedFluent<TValue>>
[src]

[src]

Create a default FluentBuilder.

impl<TValue, TStack, TFluent> FluentBuilder<TValue, TStack, TFluent>
[src]

[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, TFluent> FluentBuilder<TValue, Stack, TFluent> where
    TFluent: Fluent<TValue>, 
[src]

[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.

[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, TFluent> FluentBuilder<TValue, Override, TFluent> where
    TFluent: Fluent<TValue>, 
[src]

[src]

Create a new StatefulFluentBuilder from the given value.

[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, TFluent> FluentBuilder<TValue, TStack, TFluent> where
    TFluent: Fluent<TValue>, 
[src]

[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.

[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, TFluent> FluentBuilder<TValue, TStack, TFluent> where
    TValue: 'static,
    TFluent: Fluent<TValue> + 'static, 
[src]

[src]

Box a fluent builder so it can be easily shared.

Trait Implementations

impl<TValue, TStack> Default for FluentBuilder<TValue, TStack, BoxedFluent<TValue>>
[src]

[src]

Returns the "default value" for a type. Read more