Struct papergrid::Grid[][src]

pub struct Grid { /* fields omitted */ }
Expand description

Grid provides a set of methods for building a text-based table

Implementations

impl Grid[src]

pub fn new(rows: usize, columns: usize) -> Self[src]

The new method creates a grid instance with default styles.

The size of the grid can not be changed after the instance is created.

Example

    use papergrid::{Grid, Entity, Settings};
    let mut grid = Grid::new(2, 2);
    let str = grid.to_string();
    assert_eq!(
         str,
         "+++\n\
          |||\n\
          +++\n\
          |||\n\
          +++\n"
    )

pub fn set(&mut self, entity: Entity, settings: Settings)[src]

Set method is responsible for modification of cell/row/column.

The method panics if incorrect cell/row/column index is given.

Example

    use papergrid::{Grid, Entity, Settings};
    let mut grid = Grid::new(2, 2);
    grid.set(Entity::Row(0), Settings::new().text("row 1"));
    grid.set(Entity::Row(1), Settings::new().text("row 2"));
    let str = grid.to_string();
    assert_eq!(
         str,
         "+-----+-----+\n\
          |row 1|row 1|\n\
          +-----+-----+\n\
          |row 2|row 2|\n\
          +-----+-----+\n"
    )

pub fn count_rows(&self) -> usize[src]

Count_rows returns an amount of rows on the grid

pub fn count_columns(&self) -> usize[src]

Count_rows returns an amount of columns on the grid

pub fn get_border_mut(&mut self, row: usize) -> &mut Border[src]

Get_border_mut returns a border for a given row. The border can be modified.

Example

   use papergrid::{Grid, Entity, Settings};
   let mut grid = Grid::new(2, 2);
   grid.set(Entity::Global, Settings::new().text("asd"));
   grid.get_border_mut(0).empty()
        .top('─', '┬', Some('┌'), Some('┐'))
        .bottom('─', '┼', Some('├'), Some('┤'))
        .inner(Some('│'), Some('│'), Some('│'));
   grid.get_border_mut(1).empty()
        .top('─', '┬', Some('┌'), Some('┐'))
        .bottom('─', '┴', Some('└'), Some('┘'))
        .inner(Some('│'), Some('│'), Some('│'));

   let str = grid.to_string();
   assert_eq!(
       str,
       "┌───┬───┐\n\
        │asd│asd│\n\
        ├───┼───┤\n\
        │asd│asd│\n\
        └───┴───┘\n"
   )

Trait Implementations

impl Display for Grid[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl RefUnwindSafe for Grid

impl Send for Grid

impl Sync for Grid

impl Unpin for Grid

impl UnwindSafe for Grid

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.