Trait StringSlice

Source
pub trait StringSlice {
    // Required methods
    fn slice(&self, range: impl RangeBounds<usize>) -> &str;
    fn try_slice(&self, range: impl RangeBounds<usize>) -> Option<&str>;
    fn substring(&self, begin: usize, end: usize) -> &str;
    fn try_substring(&self, begin: usize, end: usize) -> Option<&str>;
}
Expand description

Provides the slice, try_slice, substring, and try_substring methods.

Required Methods§

Source

fn slice(&self, range: impl RangeBounds<usize>) -> &str

Returns a string slice for the given range of characters

This method will panic if the range is invalid, for example if the beginning is greater than the end.

§Examples
use stringslice::StringSlice;

assert_eq!("Ùníc😎de".slice(4..5), "😎");
Source

fn try_slice(&self, range: impl RangeBounds<usize>) -> Option<&str>

Returns an Option containing string slice for the given range of characters

This method will return None if the range is invalid, for example if the beginning is greater than the end.

§Examples
use stringslice::StringSlice;

assert_eq!("Ùníc😎de".try_slice(4..5), Some("😎"));
Source

fn substring(&self, begin: usize, end: usize) -> &str

Returns a string slice between the given beginning and end characters

This method will panic if the parameters are invalid, for example if the beginning is greater than the end.

§Examples
use stringslice::StringSlice;

assert_eq!("Ùníc😎de".substring(4, 5), "😎");
Source

fn try_substring(&self, begin: usize, end: usize) -> Option<&str>

Returns an Option containing string slice between the given beginning and end characters

This method will return None if the parameters are invalid, for example if the beginning is greater than the end.

§Examples
use stringslice::StringSlice;

assert_eq!("Ùníc😎de".try_substring(4, 5), Some("😎"));

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 StringSlice for str

Source§

fn slice(&self, range: impl RangeBounds<usize>) -> &str

Source§

fn try_slice(&self, range: impl RangeBounds<usize>) -> Option<&str>

Source§

fn substring(&self, begin: usize, end: usize) -> &str

Source§

fn try_substring(&self, begin: usize, end: usize) -> Option<&str>

Implementors§