StrExt

Trait StrExt 

Source
pub trait StrExt {
    // Required methods
    fn view(&self) -> StringView<'_>;
    fn view_part(&self, start_idx: usize, end_idx: usize) -> StringView<'_>;
    fn char_idx(&self, ch: Char<'_>) -> (usize, usize);
    fn chars_in_place(&self) -> CharsInPlace<'_> ;
    fn chars_in_place_mut(&mut self) -> CharsInPlaceMut<'_> ;
}

Required Methods§

Source

fn view(&self) -> StringView<'_>

Source

fn view_part(&self, start_idx: usize, end_idx: usize) -> StringView<'_>

Source

fn char_idx(&self, ch: Char<'_>) -> (usize, usize)

Byte index of this Char start & end inside base str.

use string_view::StrExt;

let text = "Hello World";
let mut chars = text.chars_in_place();

let first_char = chars.next().unwrap();
assert_eq!(first_char.as_str(), "H");
assert_eq!(text.char_idx(first_char), (0, 1));

let second_char = chars.next().unwrap();
assert_eq!(second_char.as_str(), "e");
assert_eq!(text.char_idx(second_char), (1, 2));
Source

fn chars_in_place(&self) -> CharsInPlace<'_>

Source

fn chars_in_place_mut(&mut self) -> CharsInPlaceMut<'_>

Implementations on Foreign Types§

Source§

impl StrExt for str

Source§

fn char_idx(&self, ch: Char<'_>) -> (usize, usize)

Byte index of this Char start & end inside base str.

use string_view::StrExt;

let text = "Hello World";
let mut chars = text.chars_in_place();

let first_char = chars.next().unwrap();
assert_eq!(first_char.as_str(), "H");
assert_eq!(text.char_idx(first_char), (0, 1));

let second_char = chars.next().unwrap();
assert_eq!(second_char.as_str(), "e");
assert_eq!(text.char_idx(second_char), (1, 2));
Source§

fn view(&self) -> StringView<'_>

Source§

fn view_part(&self, start_idx: usize, end_idx: usize) -> StringView<'_>

Source§

fn chars_in_place(&self) -> CharsInPlace<'_>

Source§

fn chars_in_place_mut(&mut self) -> CharsInPlaceMut<'_>

Implementors§