Struct stry_common::utils::slice::Slice[][src]

pub struct Slice<'s> { /* fields omitted */ }

A ‘lazy’ str slice using Ranges.

Implementations

impl<'s> Slice<'s>[src]

pub const fn new(source: &'s str) -> Slice<'s>[src]

pub const fn len(&self) -> usize[src]

Returns the length of self.

This length is in bytes, not chars or graphemes. In other words, it may not be what a human considers the length of the string.

Examples

Basic usage:

let len = Slice::new("foo").len();
assert_eq!(3, len);

assert_eq!(Slice::new("ƒoo").len(), 4); // fancy f!

pub const fn is_empty(&self) -> bool[src]

Returns true if self has a length of zero bytes.

Examples

Basic usage:

let s = Slice::new("");
assert!(s.is_empty());

let s = Slice::new("not empty");
assert!(!s.is_empty());

pub fn starts_with<'r, P, F>(&self, pat: P) -> bool where
    P: Into<Pattern<'r, F>>,
    F: FnMut(char) -> bool
[src]

Returns true if the given pattern matches a prefix of this string slice.

Returns false if it does not.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

Examples

Basic usage:

let bananas = Slice::new("bananas");

assert!(bananas.starts_with("bana"));
assert!(!bananas.starts_with("nana"));

pub fn ends_with<'r, P, F>(&self, pat: P) -> bool where
    P: Into<Pattern<'r, F>>,
    F: FnMut(char) -> bool
[src]

Returns true if the given pattern matches a suffix of this string slice.

Returns false if it does not.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

Examples

Basic usage:

let bananas = Slice::new("bananas");

assert!(bananas.ends_with("anas"));
assert!(!bananas.ends_with("nana"));

pub fn contains<'r, P, F>(&self, pat: P) -> bool where
    P: Into<Pattern<'r, F>>,
    F: FnMut(char) -> bool
[src]

Returns true if the given pattern matches a sub-slice of this string slice.

Returns false if it does not.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

Examples

Basic usage:

let bananas = Slice::new("bananas");

assert!(bananas.contains("nana"));
assert!(!bananas.contains("apples"));

pub fn trim(&self) -> Slice<'s>[src]

Returns a string slice with leading and trailing whitespace removed.

‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property White_Space.

Examples

Basic usage:

let s = Slice::new(" Hello\tworld\t");

assert_eq!("Hello\tworld", s.trim().slice());

pub fn trim_start(&self) -> Slice<'s>[src]

Returns a string slice with leading whitespace removed.

‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property White_Space.

Text directionality

A string is a sequence of bytes. start in this context means the first position of that byte string; for a left-to-right language like English or Russian, this will be left side, and for right-to-left languages like Arabic or Hebrew, this will be the right side.

Examples

Basic usage:

let s = Slice::new(" Hello\tworld\t");
assert_eq!("Hello\tworld\t", s.trim_start().slice());

Directionality:

let s = Slice::new("  English  ");
assert!(Some('E') == s.trim_start().slice().chars().next());

let s = Slice::new("  עברית  ");
assert!(Some('ע') == s.trim_start().slice().chars().next());

pub fn trim_end(&self) -> Slice<'s>[src]

Returns a string slice with trailing whitespace removed.

‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property White_Space.

Text directionality

A string is a sequence of bytes. end in this context means the last position of that byte string; for a left-to-right language like English or Russian, this will be right side, and for right-to-left languages like Arabic or Hebrew, this will be the left side.

Examples

Basic usage:

let s = Slice::new(" Hello\tworld\t");
assert_eq!(" Hello\tworld", s.trim_end().slice());

Directionality:

let s = Slice::new("  English  ");
assert!(Some('h') == s.trim_end().slice().chars().rev().next());

let s = Slice::new("  עברית  ");
assert!(Some('ת') == s.trim_end().slice().chars().rev().next());

pub fn index<R>(&self, range: R) -> Slice<'s> where
    R: Into<Ranges>, 
[src]

It isn’t possible to return a owned Slice from a Index, so you have to use this function.

pub fn slice(self) -> &'s str[src]

Consume and ‘run’ the slice, returning the given range of the source str.

Trait Implementations

impl<'s> Clone for Slice<'s>[src]

impl<'s> Debug for Slice<'s>[src]

impl<'s> Display for Slice<'s>[src]

impl<'s> Eq for Slice<'s>[src]

impl<'s> Hash for Slice<'s>[src]

impl<'s> PartialEq<Slice<'s>> for Slice<'s>[src]

impl<'s> StructuralEq for Slice<'s>[src]

impl<'s> StructuralPartialEq for Slice<'s>[src]

Auto Trait Implementations

impl<'s> RefUnwindSafe for Slice<'s>

impl<'s> Send for Slice<'s>

impl<'s> Sync for Slice<'s>

impl<'s> Unpin for Slice<'s>

impl<'s> UnwindSafe for Slice<'s>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,