Skip to main content

List

Struct List 

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

A bulleted or ordered list.

Implementations§

Source§

impl List

Source

pub fn new() -> Self

Creates an empty bulleted list.

Examples found in repository?
examples/output_gallery.rs (line 139)
135fn lists_and_trees() -> Result<()> {
136    section("Lists & trees")?;
137    List::ordered(Marker::Number)
138        .item("First step")
139        .item_with("Second step", List::new().item("detail a").item("detail b"))
140        .item("Third step")
141        .print()?;
142    println!();
143    List::ordered(Marker::AlphaLower)
144        .item("alpha")
145        .item("beta")
146        .print()?;
147    List::ordered(Marker::RomanUpper)
148        .item("one")
149        .item("two")
150        .print()?;
151    println!();
152    Tree::new()
153        .node(
154            TreeNode::new("project")
155                .child(TreeNode::new("src").child(TreeNode::new("main.rs")))
156                .child(TreeNode::new("Cargo.toml")),
157        )
158        .print()?;
159    Ok(())
160}
Source

pub fn ordered(marker: Marker) -> Self

Creates an empty list with the given marker style.

Ordered markers default to a . suffix.

Examples found in repository?
examples/output_gallery.rs (line 137)
135fn lists_and_trees() -> Result<()> {
136    section("Lists & trees")?;
137    List::ordered(Marker::Number)
138        .item("First step")
139        .item_with("Second step", List::new().item("detail a").item("detail b"))
140        .item("Third step")
141        .print()?;
142    println!();
143    List::ordered(Marker::AlphaLower)
144        .item("alpha")
145        .item("beta")
146        .print()?;
147    List::ordered(Marker::RomanUpper)
148        .item("one")
149        .item("two")
150        .print()?;
151    println!();
152    Tree::new()
153        .node(
154            TreeNode::new("project")
155                .child(TreeNode::new("src").child(TreeNode::new("main.rs")))
156                .child(TreeNode::new("Cargo.toml")),
157        )
158        .print()?;
159    Ok(())
160}
More examples
Hide additional examples
examples/output-readme.rs (line 117)
116fn middle_column() -> Rendered {
117    let list = List::ordered(Marker::Number)
118        .marker_style(Style::new().fg(Color::Yellow).bold())
119        .item("Compose widgets side by side")
120        .item("Capture, pad, and align them")
121        .item("Style with Rich-style markup")
122        .item("Render to any UTF-8 terminal")
123        .render(36);
124
125    let tree = Tree::new()
126        .dashes(2)
127        .connector_style(Style::new().fg(Color::Cyan))
128        .node(
129            TreeNode::new("project/")
130                .child(
131                    TreeNode::new("api/")
132                        .child(TreeNode::new("routes.c"))
133                        .child(TreeNode::new("auth.c")),
134                )
135                .child(TreeNode::new("worker.c"))
136                .child(TreeNode::new("store.c")),
137        )
138        .render(18);
139
140    let rules = vstack(
141        &[
142            rule("Pipeline", BorderType::Single, Color::Magenta),
143            blank(),
144            rule("Workers", BorderType::Double, Color::Green),
145            blank(),
146            rule("Storage", BorderType::Thick, Color::Yellow),
147            blank(),
148        ],
149        0,
150    );
151
152    let tree_and_rules = Columns::new()
153        .add_rendered(tree)
154        .add_rendered(rules)
155        .gap(2)
156        .render(40);
157
158    vstack(&[list, blank(), tree_and_rules], 0)
159}
Source

pub fn item(self, content: impl Into<Text>) -> Self

Adds a leaf item.

Examples found in repository?
examples/output_gallery.rs (line 138)
135fn lists_and_trees() -> Result<()> {
136    section("Lists & trees")?;
137    List::ordered(Marker::Number)
138        .item("First step")
139        .item_with("Second step", List::new().item("detail a").item("detail b"))
140        .item("Third step")
141        .print()?;
142    println!();
143    List::ordered(Marker::AlphaLower)
144        .item("alpha")
145        .item("beta")
146        .print()?;
147    List::ordered(Marker::RomanUpper)
148        .item("one")
149        .item("two")
150        .print()?;
151    println!();
152    Tree::new()
153        .node(
154            TreeNode::new("project")
155                .child(TreeNode::new("src").child(TreeNode::new("main.rs")))
156                .child(TreeNode::new("Cargo.toml")),
157        )
158        .print()?;
159    Ok(())
160}
More examples
Hide additional examples
examples/output-readme.rs (line 119)
116fn middle_column() -> Rendered {
117    let list = List::ordered(Marker::Number)
118        .marker_style(Style::new().fg(Color::Yellow).bold())
119        .item("Compose widgets side by side")
120        .item("Capture, pad, and align them")
121        .item("Style with Rich-style markup")
122        .item("Render to any UTF-8 terminal")
123        .render(36);
124
125    let tree = Tree::new()
126        .dashes(2)
127        .connector_style(Style::new().fg(Color::Cyan))
128        .node(
129            TreeNode::new("project/")
130                .child(
131                    TreeNode::new("api/")
132                        .child(TreeNode::new("routes.c"))
133                        .child(TreeNode::new("auth.c")),
134                )
135                .child(TreeNode::new("worker.c"))
136                .child(TreeNode::new("store.c")),
137        )
138        .render(18);
139
140    let rules = vstack(
141        &[
142            rule("Pipeline", BorderType::Single, Color::Magenta),
143            blank(),
144            rule("Workers", BorderType::Double, Color::Green),
145            blank(),
146            rule("Storage", BorderType::Thick, Color::Yellow),
147            blank(),
148        ],
149        0,
150    );
151
152    let tree_and_rules = Columns::new()
153        .add_rendered(tree)
154        .add_rendered(rules)
155        .gap(2)
156        .render(40);
157
158    vstack(&[list, blank(), tree_and_rules], 0)
159}
Source

pub fn item_with(self, content: impl Into<Text>, children: List) -> Self

Adds an item with a nested sub-list.

Examples found in repository?
examples/output_gallery.rs (line 139)
135fn lists_and_trees() -> Result<()> {
136    section("Lists & trees")?;
137    List::ordered(Marker::Number)
138        .item("First step")
139        .item_with("Second step", List::new().item("detail a").item("detail b"))
140        .item("Third step")
141        .print()?;
142    println!();
143    List::ordered(Marker::AlphaLower)
144        .item("alpha")
145        .item("beta")
146        .print()?;
147    List::ordered(Marker::RomanUpper)
148        .item("one")
149        .item("two")
150        .print()?;
151    println!();
152    Tree::new()
153        .node(
154            TreeNode::new("project")
155                .child(TreeNode::new("src").child(TreeNode::new("main.rs")))
156                .child(TreeNode::new("Cargo.toml")),
157        )
158        .print()?;
159    Ok(())
160}
Source

pub fn bullet(self, glyph: impl Into<String>) -> Self

Sets a custom bullet glyph (bullet marker only).

Source

pub fn marker_style(self, style: Style) -> Self

Sets the marker style.

Examples found in repository?
examples/output-readme.rs (line 118)
116fn middle_column() -> Rendered {
117    let list = List::ordered(Marker::Number)
118        .marker_style(Style::new().fg(Color::Yellow).bold())
119        .item("Compose widgets side by side")
120        .item("Capture, pad, and align them")
121        .item("Style with Rich-style markup")
122        .item("Render to any UTF-8 terminal")
123        .render(36);
124
125    let tree = Tree::new()
126        .dashes(2)
127        .connector_style(Style::new().fg(Color::Cyan))
128        .node(
129            TreeNode::new("project/")
130                .child(
131                    TreeNode::new("api/")
132                        .child(TreeNode::new("routes.c"))
133                        .child(TreeNode::new("auth.c")),
134                )
135                .child(TreeNode::new("worker.c"))
136                .child(TreeNode::new("store.c")),
137        )
138        .render(18);
139
140    let rules = vstack(
141        &[
142            rule("Pipeline", BorderType::Single, Color::Magenta),
143            blank(),
144            rule("Workers", BorderType::Double, Color::Green),
145            blank(),
146            rule("Storage", BorderType::Thick, Color::Yellow),
147            blank(),
148        ],
149        0,
150    );
151
152    let tree_and_rules = Columns::new()
153        .add_rendered(tree)
154        .add_rendered(rules)
155        .gap(2)
156        .render(40);
157
158    vstack(&[list, blank(), tree_and_rules], 0)
159}
Source

pub fn indent(self, indent: u16) -> Self

Sets the left indent in columns.

Source

pub fn item_gap(self, gap: u16) -> Self

Sets the number of blank lines between items.

Source

pub fn margin(self, margin: Edges) -> Self

Sets the outer margin.

Trait Implementations§

Source§

impl Default for List

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Renderable for List

Source§

fn render(&self, _max_width: u16) -> Rendered

Lays the value out for a terminal at most max_width columns wide.
Source§

fn print(&self) -> Result<()>

Renders at the current terminal width and prints to standard output. Read more
Source§

fn print_to<W: Write>(&self, writer: &mut W) -> Result<()>

Renders at the current terminal width and writes to writer. Read more

Auto Trait Implementations§

§

impl Freeze for List

§

impl RefUnwindSafe for List

§

impl Send for List

§

impl Sync for List

§

impl Unpin for List

§

impl UnsafeUnpin for List

§

impl UnwindSafe for List

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.