Struct Cell

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

Implementation of RawCell that can specify styles.

Implementations§

Source§

impl<T: RawCell> Cell<T>

Source

pub fn new(source: T) -> Self

Create a new Cell with specified RawCell.

Source

pub fn left(self) -> Self

Return the cell with horizontal alignment set to the left.

Source

pub fn right(self) -> Self

Return the cell with horizontal alignment set to the right.

Source

pub fn center(self) -> Self

Return the cell with horizontal alignment set to the center.

Source

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

Return the cell with aligned baseline.

use text_grid::*;

struct Source(&'static str);

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

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: RawCell> Cells for Cell<T>

Source§

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

Define columns. see CellsFormatter for details.
Source§

impl<T: RawCell> RawCell 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

Auto Trait Implementations§

§

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

§

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 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.