pub struct OptionValues { /* private fields */ }Expand description
The option values set in one place: at most one value per option type.
A caller fills one in to set option values on a document
(Doc::with_options) or on a
render request
(PlanRequest::render_options).
Values are stored under the Rust type of the option struct, so setting a
value needs no name and cannot be misspelled. Whether an option type may be
set in that place is checked later, by validate_values, when a run is
constructed or a plan is built.
§Examples
use flm_core::model::options::OptionValues;
#[derive(Debug, Default, Hash, PartialEq, Eq)]
struct Width(u32);
let values = OptionValues::new().with(Width(72));
assert_eq!(values.get::<Width>(), Some(&Width(72)));
assert_eq!(values.len(), 1);Implementations§
Source§impl OptionValues
impl OptionValues
Sourcepub fn new() -> OptionValues
pub fn new() -> OptionValues
A collection with no value set.
Sourcepub fn set<T: Options>(&mut self, value: T)
pub fn set<T: Options>(&mut self, value: T)
Sets value as the value of the option type T, replacing any value
set for T before.
Sourcepub fn with<T: Options>(self, value: T) -> OptionValues
pub fn with<T: Options>(self, value: T) -> OptionValues
Builder: sets value as the value of the option type T, as
OptionValues::set does.
Sourcepub fn get<T: Options>(&self) -> Option<&T>
pub fn get<T: Options>(&self) -> Option<&T>
The value set for the option type T in this collection, or None
when none is set.
This reads what was set in this one place. A stage may read another
value: it reads through ResolvedOptions, which may give the value
set in the other place or the type’s default.
Sourcepub fn set_named(&mut self, name: impl Into<Name>, value: Value)
pub fn set_named(&mut self, name: impl Into<Name>, value: Value)
Sets value as the value of the option type declared from data under
the name name, replacing any value set for it before. The value is
stored as a DataValue.
Sourcepub fn get_named(&self, name: &str) -> Option<&Value>
pub fn get_named(&self, name: &str) -> Option<&Value>
The value set for the option type declared from data under the name
name in this collection, or None when none is set. As for
get, a stage reads through ResolvedOptions
instead.
Sourcepub fn get_erased(&self, key: &OptionKey) -> Option<&Arc<dyn Any + Send + Sync>>
pub fn get_erased(&self, key: &OptionKey) -> Option<&Arc<dyn Any + Send + Sync>>
The value set for the option type key, with its type erased, or
None when none is set. For a caller that holds a key rather than the
Rust type.
Sourcepub fn merge_from(&mut self, other: &OptionValues)
pub fn merge_from(&mut self, other: &OptionValues)
Copies every value of other into this collection, replacing the value
of each option type that other sets and leaving the others unchanged.
Each value is replaced whole: it is never combined field by field with the value it replaces. Use this to let a caller’s own values replace, option type by option type, a set of values supplied together.
Sourcepub fn keys(&self) -> impl Iterator<Item = OptionKey> + '_
pub fn keys(&self) -> impl Iterator<Item = OptionKey> + '_
The option types that have a value set, in key order.
Sourcepub fn digest(&self) -> u64
pub fn digest(&self) -> u64
The digest of the whole collection: the option types and their values, in key order.
Two collections that set the same values give the same number, in every
process and every build. The digest of a plan request’s render option
values is part of the plan’s identity
(PlanKey), so plans built with different
render option values are different plans.
Trait Implementations§
Source§impl Clone for OptionValues
impl Clone for OptionValues
Source§impl Debug for OptionValues
impl Debug for OptionValues
Auto Trait Implementations§
impl !RefUnwindSafe for OptionValues
impl !UnwindSafe for OptionValues
impl Forget for OptionValues
impl Freeze for OptionValueswhere
*const LeafNode<OptionKey, OptionValue> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(OptionKey, OptionValue)>>: Freeze,
impl Move for OptionValues
impl Send for OptionValues
impl Sync for OptionValues
impl Unpin for OptionValues
impl UnsafeUnpin for OptionValueswhere
*const LeafNode<OptionKey, OptionValue> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(OptionKey, OptionValue)>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more