WidthSliceable

Trait WidthSliceable 

Source
pub trait WidthSliceable {
    type Output: Sized;

    // Required method
    fn slice_width<R>(&self, range: R) -> Option<Self::Output>
       where R: RangeBounds<usize>;
}
Expand description

Provides a function for slicing by grapheme width rather than bytes.

This is useful for ensuring that a text object fits in a given terminal width.

Required Associated Types§

Required Methods§

Source

fn slice_width<R>(&self, range: R) -> Option<Self::Output>
where R: RangeBounds<usize>,

Slice an object by width rather than by bytes.

§Example
use stylish_stringlike::text::WidthSliceable;
let foo = String::from("foobar");
assert_eq!(Some(String::from("oob")), foo.slice_width(1..4));
let bar = String::from("🙈🙉🙊");
// Monkeys are two columns wide, so we get nothing back
assert_eq!(None, bar.slice_width(..1));
// We get one monkey for two columns
assert_eq!(Some(String::from("🙈")), bar.slice_width(..2));
// If we aren't column-aligned, we get nothing because no one monkey fits between 1 and 3
assert_eq!(None, bar.slice_width(1..3));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> WidthSliceable for Option<T>
where T: WidthSliceable,

Source§

type Output = <T as WidthSliceable>::Output

Source§

fn slice_width<R>(&self, range: R) -> Option<Self::Output>
where R: RangeBounds<usize>,

Implementors§

Source§

impl<'a, T, U> WidthSliceable for Repeat<'a, T>
where T: BoundedWidth + WidthSliceable<Output = T> + Joinable<T, Output = U>, U: Default + Joinable<U, Output = U> + Joinable<T, Output = U> + BoundedWidth + 'a,

Source§

impl<T> WidthSliceable for T
where T: RawText + Sliceable + Sized,