tabled

Struct Extract

Source
pub struct Extract<R, C> { /* private fields */ }
Expand description

Returns a new Table that reflects a segment of the referenced Table

§Example

use tabled::{Table, format::Format, object::Rows, Modify, Extract};

let data = vec![
    (0, "Grodno", true),
    (1, "Minsk", true),
    (2, "Hamburg", false),
    (3, "Brest", true),
];

let table = Table::new(&data)
               .with(Modify::new(Rows::new(1..)).with(Format::new(|s| format!(": {} :", s))))
               .with(Extract::segment(1..=2, 1..))
               .to_string();

assert_eq!(table, "+------------+----------+\n\
                   | : Grodno : | : true : |\n\
                   +------------+----------+\n\
                   | : Minsk :  | : true : |\n\
                   +------------+----------+");

Implementations§

Source§

impl<R, C> Extract<R, C>

Source

pub fn segment(rows: R, columns: C) -> Self

Returns a new Table that reflects a segment of the referenced Table

let rows = 1..3;
let columns = 1..;
Extract::segment(rows, columns);
§Range

A RangeBounds argument can be less than or equal to the shape of a Table

If a RangeBounds argument is malformed or too large the thread will panic

// Empty                         Full                      Out of bounds
   Extract::segment(0..0, 0..0)  Extract::segment(.., ..)  Extract::segment(0..1, ..4)
   [].   .   .                   [O   O   O                [O   O   O  X] //ERROR            
     .   .   .                    O   O   O                 .   .   .             
     .   .   .                    O   O   O]                .   .   .          
Source§

impl<R> Extract<R, RangeFull>
where R: RangeBounds<usize>,

Source

pub fn rows(rows: R) -> Self

Returns a new Table that reflects a segment of the referenced Table

The segment is defined by RangeBounds for Rows

Extract::rows(1..3);
§Range

A RangeBounds argument can be less than or equal to the shape of a Table

If a RangeBounds argument is malformed or too large the thread will panic

// Empty                Full               Out of bounds
   Extract::rows(0..0)  Extract::rows(..)  Extract::rows(0..4)
   [].   .   .          [O   O   O         [O   O   O             
     .   .   .           O   O   O          O   O   O              
     .   .   .           O   O   O]         O   O   O
                                            X   X   X] // ERROR          
Source§

impl<C> Extract<RangeFull, C>
where C: RangeBounds<usize>,

Source

pub fn columns(columns: C) -> Self

Returns a new Table that reflects a segment of the referenced Table

The segment is defined by RangeBounds for Columns

Extract::columns(1..3);
§Range

A RangeBounds argument can be less than or equal to the shape of a Table

If a RangeBounds argument is malformed or too large the thread will panic

// Empty                   Full                  Out of bounds
   Extract::columns(0..0)  Extract::columns(..)  Extract::columns(0..4)
   [].   .   .             [O   O   O            [O   O   O   X          
     .   .   .              O   O   O             O   O   O   X          
     .   .   .              O   O   O]            O   O   O   X] // ERROR

Trait Implementations§

Source§

impl<R: Debug, C: Debug> Debug for Extract<R, C>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<R, C, RR> TableOption<RR> for Extract<R, C>

Source§

fn change(&mut self, table: &mut Table<RR>)

The function modifies a Grid object.

Auto Trait Implementations§

§

impl<R, C> Freeze for Extract<R, C>
where R: Freeze, C: Freeze,

§

impl<R, C> RefUnwindSafe for Extract<R, C>

§

impl<R, C> Send for Extract<R, C>
where R: Send, C: Send,

§

impl<R, C> Sync for Extract<R, C>
where R: Sync, C: Sync,

§

impl<R, C> Unpin for Extract<R, C>
where R: Unpin, C: Unpin,

§

impl<R, C> UnwindSafe for Extract<R, C>
where R: UnwindSafe, C: 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.