[−][src]Struct ibuilder::Builder
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 Choice
s (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.
Methods
impl<T: 'static> Builder<T>
[src]
pub fn from_buildable_value(inner: Box<dyn BuildableValue>) -> Builder<T>
[src]
Create a new builder from a BuildableValue
. Note that the inner type of the
BuildableValue
must match T
, otherwise a panic is very likely.
pub fn get_options(&self) -> Options
[src]
Return all the valid options that this builder accepts in the current state.
pub fn choose(&mut self, input: Input) -> Result<Option<T>, ChooseError>
[src]
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.
pub fn finalize(&self) -> Result<T, FinalizeError>
[src]
If the process is done try to finalize the process, even if the user hasn't completed the the selection yet.
pub fn is_done(&self) -> bool
[src]
Check if all the fields have been set and the call to finalize()
will be successful.
pub fn to_node(&self) -> Node
[src]
Return the tree structure of the Builder
internal state.
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for Builder<T>
impl<T> !Send for Builder<T>
impl<T> !Sync for Builder<T>
impl<T> Unpin for Builder<T> where
T: Unpin,
T: Unpin,
impl<T> !UnwindSafe for Builder<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,