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§
Trait Implementations§
Source§impl Ord for CainStr<'_>
impl Ord for CainStr<'_>
Source§impl PartialOrd for CainStr<'_>
impl PartialOrd for CainStr<'_>
impl<'a> Eq for CainStr<'a>
Auto Trait Implementations§
impl<'a> Freeze for CainStr<'a>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more