quork/traits/truncate.rs
1//! Implement truncation for types
2
3use crate::truncate::Truncate;
4
5/// Truncate the data when formatting
6pub trait Truncation
7where
8 Self: Sized + core::fmt::Display,
9{
10 /// Truncate the data
11 ///
12 /// # Examples
13 ///
14 /// ```rust
15 /// # use quork::truncate::Truncation;
16 /// let name = "Juliette Cordor".truncate(8);
17 ///
18 /// assert_eq!(name.to_string(), "Juliette");
19 /// ```
20 fn truncate(self, length: usize) -> Truncate<Self> {
21 Truncate::new(self, length)
22 }
23}
24
25impl<T: core::fmt::Display> Truncation for T {}