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 a HashSet, it doesn’t have to generate any string again and again…
  • Implementations of From<&'a str>, From<&'a String> and From<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

Converts self into the lowercase form of source string

This function simply takes the inner field out. There is no allocation.

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.