rclrs

Struct ParameterBuilder

Source
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>

Source

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.

Source

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.

Source

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.

Source

pub fn discriminate<F>(self, f: F) -> Self
where F: FnOnce(AvailableValues<'_, T>) -> Option<T> + 'a,

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().

Source

pub fn range(self, range: T::Range) -> Self

Sets the range for the parameter.

Source

pub fn description(self, description: impl Into<Arc<str>>) -> Self

Sets the parameter’s human readable description.

Source

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.

Source

pub fn mandatory(self) -> Result<MandatoryParameter<T>, DeclarationError>

Declares the parameter as a Mandatory parameter, that must always have a value.

§See also
Source

pub fn read_only(self) -> Result<ReadOnlyParameter<T>, DeclarationError>

Declares the parameter as a ReadOnly parameter, that cannot be edited.

§See also
Source

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]>>

Source

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>]>>

Source

pub fn default_string_array<U>(self, default_value: U) -> Self
where U: IntoIterator, U::Item: Into<Arc<str>>,

Sets the default for the parameter from a string-like array.

Trait Implementations§

Source§

impl<T: ParameterVariant> TryFrom<ParameterBuilder<'_, T>> for OptionalParameter<T>

Source§

type Error = DeclarationError

The type returned in the event of a conversion error.
Source§

fn try_from(builder: ParameterBuilder<'_, T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a, T: ParameterVariant + 'a> TryFrom<ParameterBuilder<'a, T>> for MandatoryParameter<T>

Source§

type Error = DeclarationError

The type returned in the event of a conversion error.
Source§

fn try_from(builder: ParameterBuilder<'_, T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a, T: ParameterVariant + 'a> TryFrom<ParameterBuilder<'a, T>> for ReadOnlyParameter<T>

Source§

type Error = DeclarationError

The type returned in the event of a conversion error.
Source§

fn try_from(builder: ParameterBuilder<'_, T>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'a, T> Freeze for ParameterBuilder<'a, T>
where T: Freeze, <T as ParameterVariant>::Range: Freeze,

§

impl<'a, T> !RefUnwindSafe for ParameterBuilder<'a, T>

§

impl<'a, T> !Send for ParameterBuilder<'a, T>

§

impl<'a, T> !Sync for ParameterBuilder<'a, T>

§

impl<'a, T> Unpin for ParameterBuilder<'a, T>
where T: Unpin, <T as ParameterVariant>::Range: Unpin,

§

impl<'a, T> !UnwindSafe for ParameterBuilder<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.