Struct stry_common::utils::slice::Slice [−][src]
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 char
s 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]
P: Into<Pattern<'r, F>>,
F: FnMut(char) -> bool,
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 char
s, 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]
P: Into<Pattern<'r, F>>,
F: FnMut(char) -> bool,
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 char
s, 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]
P: Into<Pattern<'r, F>>,
F: FnMut(char) -> bool,
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 char
s, 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]
R: Into<Ranges>,
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]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[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]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,