pub struct Builder<T> { /* private fields */ }Expand description
Interactive builder for creating instances of the struct T by communicating. To instantiate a
new Builder for the type T, make T derive from IBuilder and call builder() on it from
the Buildable trait.
§Communication
After having instantiated a new Builder<T> you can call the get_options() method for
fetching the list of possible actions that can be done to update the builder. Those options are
like menu entries used to move between menus and set the value of the fields.
The Options struct contains a list of possible Choices (like buttons to press) and
eventually allow raw text input (like a textbox). For example while editing an integer field
the user can insert the new value of the number as a text or can choose to go back to the
previous menu by pressing on “back”.
The user’s input is communicated to the Builder via the choose method. It takes an Input,
a container with the choice of the user, which can be either some Text (if the Options
allowed it), or a Choice (whose content is the identifier of the selected option between the
ones in the Options).
When the user has filled all the fields of the builder, he can select the “done” options, which
will make the choose method return Ok(Some(T)), signaling the end of the communication.
Implementations§
Source§impl<T: 'static> Builder<T>
impl<T: 'static> Builder<T>
Sourcepub fn from_buildable_value(inner: Box<dyn BuildableValue>) -> Builder<T>
pub fn from_buildable_value(inner: Box<dyn BuildableValue>) -> Builder<T>
Create a new builder from a BuildableValue. Note that the inner type of the
BuildableValue must match T, otherwise a panic is very likely.
Sourcepub fn get_options(&self) -> Options
pub fn get_options(&self) -> Options
Return all the valid options that this builder accepts in the current state.
Sourcepub fn choose(&mut self, input: Input) -> Result<Option<T>, ChooseError>
pub fn choose(&mut self, input: Input) -> Result<Option<T>, ChooseError>
Apply an input to the builder, making it change state. Call again get_options() for the
new options.
Returns Ok(None) if the process is not done yet, Ok(Some(T)) when the user choose to
finish the builder.
Sourcepub fn finalize(&self) -> Result<T, FinalizeError>
pub fn finalize(&self) -> Result<T, FinalizeError>
If the process is done try to finalize the process, even if the user hasn’t completed the the selection yet.