pub struct Truncate;
stdlib
only.Expand description
truncate
shortens a string down to the number of characters passed as a parameter.
Note that this function operates on grapheme clusters (or user-perceived character), rather than Unicode code points. Each grapheme cluster may be composed of more than one Unicode code point, and does not necessarily correspond to rust’s conception of a character.
If the number of characters specified is less than the length of the string, an ellipsis
(...
) is appended to the string and is included in the character count.
§Custom ellipsis
truncate
takes an optional second parameter that specifies the sequence of characters to be
appended to the truncated string. By default this is an ellipsis (...
), but you can specify a
different sequence.
The length of the second parameter counts against the number of characters specified by the
first parameter. For example, if you want to truncate a string to exactly 10 characters, and
use a 3-character ellipsis, use 13 for the first parameter of truncate
, since the ellipsis
counts as 3 characters.
§No ellipsis
You can truncate to the exact number of characters specified by the first parameter and show no trailing characters by passing a blank string as the second parameter.
Trait Implementations§
Source§impl FilterReflection for Truncate
impl FilterReflection for Truncate
fn name(&self) -> &'static str
fn description(&self) -> &'static str
fn positional_parameters(&self) -> &'static [ParameterReflection]
fn keyword_parameters(&self) -> &'static [ParameterReflection]
Source§impl ParseFilter for Truncate
impl ParseFilter for Truncate
Source§fn parse(&self, args: FilterArguments<'_>) -> Result<Box<dyn Filter>>
fn parse(&self, args: FilterArguments<'_>) -> Result<Box<dyn Filter>>
input
based on arguments
.fn reflection(&self) -> &dyn FilterReflection
Auto Trait Implementations§
impl Freeze for Truncate
impl RefUnwindSafe for Truncate
impl Send for Truncate
impl Sync for Truncate
impl Unpin for Truncate
impl UnwindSafe for Truncate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> ParseFilterClone for Twhere
T: 'static + ParseFilter + Clone,
impl<T> ParseFilterClone for Twhere
T: 'static + ParseFilter + Clone,
Source§fn clone_box(&self) -> Box<dyn ParseFilter>
fn clone_box(&self) -> Box<dyn ParseFilter>
dyn ParseFilter
.