tabled::width

Struct Truncate

Source
pub struct Truncate<'a, W = usize, P = PriorityNone> { /* private fields */ }
Expand description

Truncate cut the string to a given width if its length exceeds it. Otherwise keeps the content of a cell untouched.

The function is color aware if a color feature is on.

Be aware that it doesn’t consider padding. So if you want to set a exact width you might need to use Padding to set it to 0.

§Example

use tabled::{object::Segment, Width, Modify, Table};

let table = Table::new(&["Hello World!"])
    .with(Modify::new(Segment::all()).with(Width::truncate(3)));

Implementations§

Source§

impl<W> Truncate<'static, W>
where W: Measurment<Width>,

Source

pub fn new(width: W) -> Truncate<'static, W>

Creates a Truncate object

Source§

impl<'a, W, P> Truncate<'a, W, P>

Source

pub fn suffix<S: Into<Cow<'a, str>>>(self, suffix: S) -> Truncate<'a, W, P>

Sets a suffix which will be appended to a resultant string.

The suffix is used in 3 circamstances: 1. If original string is bigger than the suffix. We cut more of the original string and append the suffix. 2. If suffix is bigger than the original string. We cut the suffix to fit in the width by default. But you can peak the behaviour by using Truncate::suffix_limit

Source

pub fn suffix_limit(self, limit: SuffixLimit) -> Truncate<'a, W, P>

Sets a suffix limit, which is used when the suffix is too big to be used.

Source§

impl<'a, W, P> Truncate<'a, W, P>

Source

pub fn priority<PP: Peaker>(self) -> Truncate<'a, W, PP>

Priority defines the logic by which a truncate will be applied when is done for the whole table.

Trait Implementations§

Source§

impl<W, P, R> CellOption<R> for Truncate<'_, W, P>

Source§

fn change_cell(&mut self, table: &mut Table<R>, entity: Entity)

Modification function of a single cell.
Source§

impl<'a, W: Debug, P: Debug> Debug for Truncate<'a, W, P>

Source§

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

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

impl<W, P, R> TableOption<R> for Truncate<'_, W, P>

Source§

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

The function modifies a Grid object.

Auto Trait Implementations§

§

impl<'a, W, P> Freeze for Truncate<'a, W, P>
where W: Freeze,

§

impl<'a, W, P> RefUnwindSafe for Truncate<'a, W, P>

§

impl<'a, W, P> Send for Truncate<'a, W, P>
where W: Send, P: Send,

§

impl<'a, W, P> Sync for Truncate<'a, W, P>
where W: Sync, P: Sync,

§

impl<'a, W, P> Unpin for Truncate<'a, W, P>
where W: Unpin, P: Unpin,

§

impl<'a, W, P> UnwindSafe for Truncate<'a, W, P>
where W: UnwindSafe, P: 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.