Struct fluent_builder::StatefulFluentBuilder [] [src]

pub struct StatefulFluentBuilder<TValue, TSeed, TStack = Override, TFluent = BoxedFluent<TValue>> { /* fields omitted */ }

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

Methods

impl<TValue, TSeed, TStack, TFluent> StatefulFluentBuilder<TValue, TSeed, TStack, TFluent>
[src]

[src]

Create a new StatefulFluentBuilder from the given value.

[src]

Create a new StatefulFluentBuilder from the given seed.

[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, TSeed, TStack> StatefulFluentBuilder<TValue, TSeed, TStack, BoxedFluent<TValue>>
[src]

[src]

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

[src]

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.

impl<TValue, TSeed, TStack, TFluent> StatefulFluentBuilder<TValue, TSeed, 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 = StatefulFluentBuilder::<String, i32, Stack>::from_value("A value".to_owned())
    .fluent(1, |s, i| 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());
    }
}

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

[src]

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.

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

[src]

Box a fluent builder so it can be easily shared.