Crate fluent_builder [−] [src]
A simple builder for constructing or mutating values.
This crate provides a simple FluentBuilder
structure.
It offers some standard behaviour for constructing values from a given source, or by mutating a default that's supplied later.
This crate is intended to be used within other builders rather than consumed by your users directly.
Usage
Create a FluentBuilder
and construct a default value:
use fluent_builder::FluentBuilder; let builder = FluentBuilder::<String>::default(); let value = builder.into_value(|| "A default value".to_owned()); assert_eq!("A default value", value);
Values can be supplied to the builder directly. In this case that value will be used instead of constructing the default:
use fluent_builder::FluentBuilder; let builder = FluentBuilder::<String>::default().value("A value".to_owned()); let value = builder.into_value(|| "A default value".to_owned()); assert_eq!("A value", value);
Mutating methods can be stacked and will either be applied to a concrete value, or the constructed default:
use fluent_builder::FluentBuilder; let builder = FluentBuilder::<String>::default() .fluent_mut(|s| s.push_str(" fluent1")) .fluent_mut(|s| s.push_str(" fluent2")); let value = builder.into_value(|| "A default value".to_owned()); assert_eq!("A default value fluent1 fluent2", value);
Structs
FluentBuilder |
A structure that can contain a value, or stack mutating methods over one supplied later. |