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<'_> ;
    fn make_lowercase(&mut self);
    fn make_uppercase(&mut self);
}

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<'_>

Source

fn make_lowercase(&mut self)

Makes str characters lowercase in-place where appropriate

Source

fn make_uppercase(&mut self)

Makes str characters uppercase in-place where appropriate

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 make_lowercase(&mut self)

Makes str characters lowercase in-place where appropriate


use string_view::StrExt;

let text: &mut str = &mut String::from("HELLO World");
text.make_lowercase();
assert_eq!(text, "hello world");
 
let text: &mut str = &mut String::from("ПРИВЕТ Мир");
text.make_lowercase();
assert_eq!(text, "привет мир");
Source§

fn make_uppercase(&mut self)

Makes str characters uppercase in-place where appropriate


use string_view::StrExt;

let text: &mut str = &mut String::from("Hello World");
text.make_uppercase();
assert_eq!(text, "HELLO WORLD");
 
let text: &mut str = &mut String::from("Привет мир");
text.make_uppercase();
assert_eq!(text, "ПРИВЕТ МИР");
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§