Trait Slice
Source pub trait Slice {
// Required method
fn slice(&self, r: impl Range) -> String;
}
Expand description
Provides the [slice()] method.
[slice()]: trait.Slice.html#tymethod.slice
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
The [slice()] method is provided for &str and takes the index-range as an argument.
It slices the &str and returns a the sliced one as a String.
Example:
let mut s = String::from("hello world!");
s = s.slice(..5);
assert_eq!("hello", s);
The [slice()] method is provided for std::string::String and takes the index-range as an argument.
It slices the String returns a new one.
Example:
let mut s = String::from("hello world!");
s = s.slice(..5);
assert_eq!("hello", s);