Slice

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

Required Methods§

Source

fn slice(&self, r: impl Range) -> String

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

Source§

fn slice(&self, r: impl Range) -> String

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);
Source§

impl Slice for String

Source§

fn slice(&self, r: impl Range) -> String

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);

Implementors§