pub struct CainStr<'a> { /* private fields */ }Expand description
Case-insensitive string
Notes
- This struct is intended for sorting in lists, or to be used in sets, so it generates a lower-case form of source string and stores it
inside. That might look like a waste of memory, but it helps with performance. For example when you call
Vec::sort()or when you insert it into aHashSet, it doesn’t have to generate any string again and again… - Implementations of
From<&'a str>,From<&'a String>andFrom<String>either borrow or take the source string and store it inside. - Implementation of
FromStrwill clone the source strings.
Examples
use std::collections::HashSet;
use sub_strs::CainStr;
let wild_data: HashSet<_> = vec!["swift", "C++", "rust", "SWIFT"].into_iter().collect();
assert_eq!(wild_data.len(), 4);
let data: HashSet<_> = wild_data.into_iter().map(|s| CainStr::from(s)).collect();
assert_eq!(data.len(), 3);
let mut data: Vec<_> = data.into_iter().collect();
data.sort();
let data: Vec<_> = data.iter().map(|cs| cs.as_ref()).collect();
assert_eq!(&data[..2], &["C++", "rust"]);
assert!(data[2].eq_ignore_ascii_case("swift"));Implementations
sourceimpl CainStr<'_>
impl CainStr<'_>
sourcepub fn into_lowercase(self) -> String
pub fn into_lowercase(self) -> String
Converts self into the lowercase form of source string
This function simply takes the inner field out. There is no allocation.
Trait Implementations
sourceimpl Ord for CainStr<'_>
impl Ord for CainStr<'_>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<CainStr<'_>> for CainStr<'_>
impl PartialEq<CainStr<'_>> for CainStr<'_>
sourceimpl PartialOrd<CainStr<'_>> for CainStr<'_>
impl PartialOrd<CainStr<'_>> for CainStr<'_>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl<'a> Eq for CainStr<'a>
impl<'a> StructuralEq for CainStr<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for CainStr<'a>
impl<'a> Send for CainStr<'a>
impl<'a> Sync for CainStr<'a>
impl<'a> Unpin for CainStr<'a>
impl<'a> UnwindSafe for CainStr<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more