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§
Sourcefn slice(&self, range: impl RangeBounds<usize>) -> &str
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), "😎");
Sourcefn substring(&self, begin: usize, end: usize) -> &str
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), "😎");
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.