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::{Table, settings::{object::Segment, Width, Modify}};

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

Implementations§

Source§

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

Source

pub const 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 circumstances: 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

pub fn multiline(self, on: bool) -> Truncate<'a, W, P>

Use trancate logic per line, not as a string as a whole.

Source§

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

Source

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

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

Source§

impl Truncate<'_, (), ()>

Source

pub fn truncate(text: &str, width: usize) -> Cow<'_, str>

Truncate a given string

Trait Implementations§

Source§

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

Source§

fn change(self, records: &mut R, cfg: &mut ColoredConfig, entity: Entity)

Modification function of a certail part of a grid targeted by Entity.
Source§

fn hint_change(&self) -> Option<Entity>

A hint whether an TableOption is going to change table layout. Read more
Source§

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

Source§

fn clone(&self) -> Truncate<'a, W, P>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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<'a, W: Ord, P: Ord> Ord for Truncate<'a, W, P>

Source§

fn cmp(&self, other: &Truncate<'a, W, P>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

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

Source§

fn eq(&self, other: &Truncate<'a, W, P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

fn partial_cmp(&self, other: &Truncate<'a, W, P>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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

Source§

fn change( self, records: &mut R, cfg: &mut ColoredConfig, dims: &mut CompleteDimension, )

The function modificaties of records and a grid configuration.
Source§

fn hint_change(&self) -> Option<Entity>

A hint whether an TableOption is going to change table layout. Read more
Source§

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

Source§

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

Auto Trait Implementations§

§

impl<'a, W, P> Freeze for Truncate<'a, W, P>
where W: Freeze, P: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.