Struct text_grid::Cell

source ·
pub struct Cell<T> { /* private fields */ }
Expand description

Implementation of CellSource that can specify styles.

Implementations§

source§

impl<T: CellSource> Cell<T>

source

pub fn new(source: T) -> Self

Create a new Cell with specified CellSource.

source

pub fn left(self) -> Self

Return the cell with horizontal alignment set to the left.

Examples found in repository?
examples/readme.rs (line 13)
10
11
12
13
14
15
16
17
18
        fn fmt(f: &mut CellsFormatter<&Self>) {
            f.column("a", |&s| &s.a);
            f.column("b", |&s| s.b);
            f.column("c", |&s| cell(s.c).left());
            f.column_with("d", |f| {
                f.column("x", |&s| s.d);
                f.column("y", |&s| cells_e!("{:.2e}", s.d));
            });
        }
source

pub fn right(self) -> Self

Return the cell with horizontal alignment set to the right.

Examples found in repository?
examples/cell_macro.rs (line 9)
8
9
10
11
        fn fmt(f: &mut CellsFormatter<&Self>) {
            f.column("a", |&s| cell!("{:.2}", s.a).right());
            f.column("b", |&s| cell!("{:.3}", s.b).right());
        }
More examples
Hide additional examples
examples/grid_buf.rs (line 5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    use text_grid::*;
    let mut g = GridBuilder::new();
    g.push(|b| {
        b.push(cell("name").right());
        b.push("type");
        b.push("value");
    });
    g.push_separator();
    g.push(|b| {
        b.push(cell(String::from("X")).right());
        b.push("A");
        b.push(10);
    });
    g.push(|b| {
        b.push(cell("Y").right());
        b.push_with_colspan(cell("BBB").center(), 2);
    });
    print!("{}", g);
}
source

pub fn center(self) -> Self

Return the cell with horizontal alignment set to the center.

Examples found in repository?
examples/grid_buf.rs (line 17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    use text_grid::*;
    let mut g = GridBuilder::new();
    g.push(|b| {
        b.push(cell("name").right());
        b.push("type");
        b.push("value");
    });
    g.push_separator();
    g.push(|b| {
        b.push(cell(String::from("X")).right());
        b.push("A");
        b.push(10);
    });
    g.push(|b| {
        b.push(cell("Y").right());
        b.push_with_colspan(cell("BBB").center(), 2);
    });
    print!("{}", g);
}
source

pub fn baseline(self, baseline: &str) -> impl CellsSource

Return the cell with aligned baseline.

use text_grid::*;

struct Source(&'static str);

impl CellsSource for Source {
    fn fmt(f: &mut CellsFormatter<&Self>) {
        f.column("default", |x| &x.0);
        f.column("baseline", |x| cell(&x.0).baseline("-"));
    }
}
let mut g = Grid::new();
g.push(&Source("1-2345"));
g.push(&Source("1234-5"));
g.push(&Source("12345"));

assert_eq!(format!("\n{g}"), r#"
 default |  baseline  |
---------|------------|
 1-2345  |     1-2345 |
 1234-5  |  1234-5    |
 12345   | 12345      |
"#);
source

pub fn with_base_style(self, style: CellStyle) -> Self

Return the cell with an empty style replaced by the specified style.

Judgment as to whether the style is empty or not is done for each individual element.

source§

impl Cell<String>

source

pub fn empty() -> Self

Create a new Cell with empty string and empty style.

Trait Implementations§

source§

impl<T: CellSource> CellSource for Cell<T>

source§

fn fmt(&self, s: &mut String)

Output the cell text to given buffer.
source§

fn style(&self) -> CellStyle

Return cell’s style.
source§

fn style_for_body(&self) -> CellStyle

source§

impl<T: CellSource> CellsSource for Cell<T>

source§

fn fmt(f: &mut CellsFormatter<'_, &Self>)

Define columns. see CellsFormatter for details.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Cell<T>where T: RefUnwindSafe,

§

impl<T> Send for Cell<T>where T: Send,

§

impl<T> Sync for Cell<T>where T: Sync,

§

impl<T> Unpin for Cell<T>where T: Unpin,

§

impl<T> UnwindSafe for Cell<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.