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
FromStr
will 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§
source§impl 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§
source§impl Ord for CainStr<'_>
impl Ord for CainStr<'_>
source§impl PartialEq<CainStr<'_>> for CainStr<'_>
impl PartialEq<CainStr<'_>> for CainStr<'_>
source§impl PartialOrd<CainStr<'_>> for CainStr<'_>
impl PartialOrd<CainStr<'_>> for CainStr<'_>
1.0.0 · source§fn 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