Trait stringslice::StringSlice[][src]

pub trait StringSlice {
    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>; }

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

Required methods

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

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), "😎");

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

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("😎"));

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

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), "😎");

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

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("😎"));
Loading content...

Implementors

impl StringSlice for str[src]

Loading content...