pub struct ParameterBuilder<'a, T: ParameterVariant> { /* private fields */ }
Expand description
Builder used to declare a parameter. Obtain this by calling
crate::Node::declare_parameter
.
Implementations§
Source§impl<'a, T: ParameterVariant> ParameterBuilder<'a, T>
impl<'a, T: ParameterVariant> ParameterBuilder<'a, T>
Sourcepub fn default(self, value: T) -> Self
pub fn default(self, value: T) -> Self
Sets the default value for the parameter. The parameter value will be initialized to this if no command line override was given for this parameter and if the parameter also had no value prior to being declared.
To customize how the initial value of the parameter is chosen, you can
provide a custom function with the method Self::discriminate()
. By
default, the initial value will be chosen as
default_value < override_value < prior_value
in order of increasing
preference.
Sourcepub fn ignore_override(self) -> Self
pub fn ignore_override(self) -> Self
Ignore any override that was given for this parameter.
If you also use Self::discriminate()
, the
AvailableValues::override_value
field given to the discriminator
will be None
even if the user had provided an override.
Sourcepub fn discard_mismatching_prior_value(self) -> Self
pub fn discard_mismatching_prior_value(self) -> Self
If the parameter was set to a value before being declared with a type
that does not match this declaration, discard the prior value instead
of emitting a DeclarationError::PriorValueTypeMismatch
.
If the type of the prior value does match the declaration, it will still be provided to the discriminator.
Sourcepub fn discriminate<F>(self, f: F) -> Self
pub fn discriminate<F>(self, f: F) -> Self
Decide what the initial value for the parameter will be based on the
available default_value
, override_value
, or prior_value
.
The default discriminator is default_initial_value_discriminator()
.
Sourcepub fn description(self, description: impl Into<Arc<str>>) -> Self
pub fn description(self, description: impl Into<Arc<str>>) -> Self
Sets the parameter’s human readable description.
Sourcepub fn constraints(self, constraints: impl Into<Arc<str>>) -> Self
pub fn constraints(self, constraints: impl Into<Arc<str>>) -> Self
Sets the parameter’s human readable constraints. These are not enforced by the library but are displayed on parameter description requests and can be used by integrators to understand complex constraints.
Sourcepub fn mandatory(self) -> Result<MandatoryParameter<T>, DeclarationError>
pub fn mandatory(self) -> Result<MandatoryParameter<T>, DeclarationError>
Declares the parameter as a Mandatory parameter, that must always have a value.
§See also
Sourcepub fn read_only(self) -> Result<ReadOnlyParameter<T>, DeclarationError>
pub fn read_only(self) -> Result<ReadOnlyParameter<T>, DeclarationError>
Declares the parameter as a ReadOnly parameter, that cannot be edited.
§See also
Sourcepub fn optional(self) -> Result<OptionalParameter<T>, DeclarationError>
pub fn optional(self) -> Result<OptionalParameter<T>, DeclarationError>
Declares the parameter as an Optional parameter, that can be unset.
This will never return the DeclarationError::NoValueAvailable
variant.
§See also
Source§impl<T> ParameterBuilder<'_, Arc<[T]>>
impl<T> ParameterBuilder<'_, Arc<[T]>>
Sourcepub fn default_from_iter(
self,
default_value: impl IntoIterator<Item = T>,
) -> Self
pub fn default_from_iter( self, default_value: impl IntoIterator<Item = T>, ) -> Self
Sets the default for an array-like parameter from an iterable.
Source§impl ParameterBuilder<'_, Arc<[Arc<str>]>>
impl ParameterBuilder<'_, Arc<[Arc<str>]>>
Sourcepub fn default_string_array<U>(self, default_value: U) -> Self
pub fn default_string_array<U>(self, default_value: U) -> Self
Sets the default for the parameter from a string-like array.