tabled

Struct Highlight

Source
pub struct Highlight<O> { /* private fields */ }
Expand description

Highlight modifies a table style by changing a border of a target Table segment.

§Example

use tabled::{TableIteratorExt, Highlight, Border, Style, object::Segment};

let data = [
    ("ELF", "Extensible Linking Format", true),
    ("DWARF", "", true),
    ("PE", "Portable Executable", false),
];

let table = data.iter()
               .enumerate()
               .table()
               .with(Style::markdown())
               .with(Highlight::new(Segment::all(), Border::default().top('^').bottom('v')))
               .to_string();

assert_eq!(
    table,
    concat!(
        " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",
        "| usize | &str  | &str                      | bool  |\n",
        "|-------|-------|---------------------------|-------|\n",
        "| 0     | ELF   | Extensible Linking Format | true  |\n",
        "| 1     | DWARF |                           | true  |\n",
        "| 2     | PE    | Portable Executable       | false |\n",
        " vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ",
    ),
);

It’s possible to use Highlight for many kinds of figures.

use tabled::{TableIteratorExt, Highlight, Border, Style, object::{Segment, Cell, Object}};

let data = [
    ("ELF", "Extensible Linking Format", true),
    ("DWARF", "", true),
    ("PE", "Portable Executable", false),
];

let table = data.iter()
               .enumerate()
               .table()
               .with(Style::markdown())
               .with(Highlight::new(Segment::all().not(Cell(0,0).and(Cell(1, 0).and(Cell(0, 1)).and(Cell(0, 3)))), Border::filled('*')))
               .to_string();

println!("{}", table);

assert_eq!(
    table,
    concat!(
        "                *****************************        \n",
        "| usize | &str  * &str                      * bool  |\n",
        "|-------*********---------------------------*********\n",
        "| 0     * ELF   | Extensible Linking Format | true  *\n",
        "*********                                           *\n",
        "* 1     | DWARF |                           | true  *\n",
        "*                                                   *\n",
        "* 2     | PE    | Portable Executable       | false *\n",
        "*****************************************************",
    ),
);

Implementations§

Source§

impl<O> Highlight<O>
where O: Object,

Source

pub fn new(target: O, border: Border) -> Self

Build a new instance of Highlight

BE AWARE: if target exceeds boundaries it may panic.

Trait Implementations§

Source§

impl<O: Debug> Debug for Highlight<O>

Source§

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

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

impl<O, R> TableOption<R> for Highlight<O>
where O: Object, R: Records,

Source§

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

The function modifies a Grid object.

Auto Trait Implementations§

§

impl<O> Freeze for Highlight<O>
where O: Freeze,

§

impl<O> RefUnwindSafe for Highlight<O>
where O: RefUnwindSafe,

§

impl<O> Send for Highlight<O>
where O: Send,

§

impl<O> Sync for Highlight<O>
where O: Sync,

§

impl<O> Unpin for Highlight<O>
where O: Unpin,

§

impl<O> UnwindSafe for Highlight<O>
where O: 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.