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>,
impl<TSeed, TValue, TStack, TStorage> StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>where
TStorage: Storage<TValue>,
Sourcepub fn from_value(value: TValue) -> Self
pub fn from_value(value: TValue) -> Self
Create a new StatefulFluentBuilder
from the given value.
Source§impl<TSeed, TValue, TStack> StatefulFluentBuilder<TSeed, TValue, TStack, DefaultStorage>
impl<TSeed, TValue, TStack> StatefulFluentBuilder<TSeed, TValue, TStack, DefaultStorage>
Sourcepub fn from_fluent<TNextStorage>(
seed: TSeed,
fluent_method: TNextStorage,
) -> StatefulFluentBuilder<TSeed, TValue, TStack, Apply<TValue, DefaultStorage, ByValue<TNextStorage>>>where
TNextStorage: FnOnce(TValue) -> TValue,
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.
Sourcepub fn from_fluent_mut<TNextStorage>(
seed: TSeed,
fluent_method: TNextStorage,
) -> StatefulFluentBuilder<TSeed, TValue, TStack, Apply<TValue, DefaultStorage, ByRefMut<TNextStorage>>>where
TNextStorage: FnOnce(&mut TValue),
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.
Sourcepub fn from_fluent<TNextStorage>(
seed: TSeed,
fluent_method: TNextStorage,
) -> StatefulFluentBuilder<TSeed, TValue, TStack, Shared>
pub fn from_fluent<TNextStorage>( seed: TSeed, fluent_method: TNextStorage, ) -> StatefulFluentBuilder<TSeed, TValue, TStack, Shared>
Create a new StatefulFluentBuilder
from the given seed and fluent method.
Sourcepub 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,
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>
impl<TSeed, TValue, TStack> StatefulFluentBuilder<TSeed, TValue, TStack, Boxed>
Sourcepub fn from_fluent<TNextStorage>(
seed: TSeed,
fluent_method: TNextStorage,
) -> StatefulFluentBuilder<TSeed, TValue, TStack, Boxed>where
TValue: 'static,
TSeed: 'static,
TNextStorage: FnOnce(TValue) -> TValue + 'static,
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.
Sourcepub 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,
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>,
impl<TSeed, TValue, TStack, TStorage> StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>where
TStorage: Storage<TValue>,
Sourcepub fn into_value<TDefault>(self, default_value: TDefault) -> TValuewhere
TDefault: FnOnce(TSeed) -> TValue + 'static,
pub fn into_value<TDefault>(self, default_value: TDefault) -> TValuewhere
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.
Sourcepub fn try_into_value(self) -> TryIntoValue<TValue, Self>
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>,
impl<TSeed, TValue, TStorage> StatefulFluentBuilder<TSeed, TValue, Stack, TStorage>where
TStorage: Storage<TValue>,
Sourcepub 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,
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.
Sourcepub 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),
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>,
impl<TSeed, TValue, TStorage> StatefulFluentBuilder<TSeed, TValue, Override, TStorage>where
TStorage: Storage<TValue>,
Sourcepub fn fluent<TNextStorage>(
self,
seed: TSeed,
fluent_method: TNextStorage,
) -> StatefulFluentBuilder<TSeed, TValue, Override, Apply<TValue, DefaultStorage, ByValue<TNextStorage>>>where
TNextStorage: FnOnce(TValue) -> TValue + 'static,
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.
Sourcepub 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,
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,
impl<TSeed, TValue, TStack, TStorage> StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>where
TSeed: 'static,
TStorage: Storage<TValue>,
TStorage::Method: 'static,
Sourcepub fn boxed(self) -> BoxedStatefulFluentBuilder<TSeed, TValue, TStack>
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,
impl<TSeed, TValue, TStack, TStorage> StatefulFluentBuilder<TSeed, TValue, TStack, TStorage>where
TSeed: 'static,
TStorage: Storage<TValue>,
TStorage::Method: Send + 'static,
Box a fluent builder so it can be easily shared.