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>,
impl<W> Truncate<'static, W>where
W: Measurment<Width>,
Source§impl<'a, W, P> Truncate<'a, W, P>
impl<'a, W, P> Truncate<'a, W, P>
Sourcepub fn suffix<S: Into<Cow<'a, str>>>(self, suffix: S) -> Truncate<'a, W, P>
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
Sourcepub fn suffix_limit(self, limit: SuffixLimit) -> Truncate<'a, W, P>
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>
impl<'a, W, P> Truncate<'a, W, P>
Sourcepub fn priority<PP: Peaker>(self) -> Truncate<'a, W, PP>
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.
PriorityNone
which cuts the columns one after another.PriorityMax
cuts the biggest columns first.PriorityMin
cuts the lowest columns first.