Skip to main content

ListBuilder

Struct ListBuilder 

Source
pub struct ListBuilder { /* private fields */ }
Expand description

ListBuilder is used to create List instances using the builder pattern. This allows for a flexible and readable way to construct List with different options by chaining method calls.

§Example

ListBuilder::new()
    .header(...)?
    .default_flags(...)?
    .number()
    .build();

Implementations§

Source§

impl ListBuilder

Source

pub fn new() -> Self

Constructs a new ListBuilder.

§Return

ListBuilder: A new instance of ListBuilder.

§Example
let _ = ListBuilder::new();
Source

pub fn header_expl(self, header: Header) -> Self

Explicitly sets a Header component for the List. Unlike the header method, which takes a label and internally constructs a Header, this method allows you to directly provide a preconstructed Header component.

§Parameters
  • header: A Header component.
§Returns
  • ListBuilder: Returns self.
§Example
// Create a `Header` component.
let header = Header::new(...)?;

// Set a preconstructed `Header` component.
ListBuilder::new()
    .header_expl(header);
Source

pub fn header(self, label: &str) -> FtuiResult<Self>

Sets a Header component for the List.

§Parameters
  • label: A &str representing the text to display in the header.
§Returns
  • Ok(ListBuilder): Returns self.
  • Err(FtuiError): Returns an error.
§Example
// Sets a `Header` component with the label "Welcome".
List::new()
    .header("Welcome")?;
Source

pub fn default_flags(self, flags: TextFlags) -> FtuiResult<Self>

Sets the default TextFlags to be used when adding elements to the List.

§Parameters
  • flags: The TextFlags to apply to elements unless explicitly overridden.
§Returns
  • Ok(ListBuilder): Returns self.
  • Err(FtuiError): Returns an error.
§Example
// Set a default red color for all elements added to the list, unless overridden.
ListBuilder::new()
    .default_flags(tui::TextFlags::COLOR_RED)?;
Source

pub fn number(self) -> Self

Enables numbering for the List, adding a number prefix to each element.

§Returns
  • Self: Returns self.
§Example
ListBuilder::new()
    .number();
Source

pub fn build(self) -> List

Finalizes the construction of a List. This method should be called after all desired options have been set using the builder pattern. It consumes self and returns the completed List.

§Returns
  • List: Returns the created List.
§Example
ListBuilder::new()
    .header(...)?
    .default_flags(...)?
    .number()
    .build(); // Finalize and retrieve the constructed list.

Auto Trait Implementations§

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.