Struct uncased::Uncased

source ·
pub struct Uncased<'s> { /* private fields */ }
Expand description

An uncased (case-insensitive, case-preserving), owned or borrowed ASCII string.

Implementations§

source§

impl<'s> Uncased<'s>

source

pub fn new<S: Into<Cow<'s, str>>>(string: S) -> Uncased<'s>

Creates a new Uncased string from string without allocating.

§Example
use uncased::Uncased;

let uncased = Uncased::new("Content-Type");
assert_eq!(uncased, "content-type");
assert_eq!(uncased, "CONTENT-Type");
source

pub const fn from_borrowed(string: &'s str) -> Uncased<'s>

Creates a new Uncased string from a borrowed string.

§Example
use uncased::Uncased;

const UNCASED: Uncased = Uncased::from_borrowed("Content-Type");
assert_eq!(UNCASED, "content-type");
assert_eq!(UNCASED, "CONTENT-Type");
source

pub const fn from_owned(string: String) -> Uncased<'s>

Creates a new Uncased string from string without allocating.

§Example
use uncased::Uncased;

const UNCASED: Uncased = Uncased::from_owned(String::new());

let uncased = Uncased::from_owned("Content-Type".to_string());
assert_eq!(uncased, "content-type");
assert_eq!(uncased, "CONTENT-Type");
source

pub fn as_uncased_str(&self) -> &UncasedStr

Converts self into an owned Uncased<'static>, allocating if necessary.

§Example
use uncased::Uncased;

let foo = "foo".to_string();
let uncased = Uncased::from(foo.as_str());
let owned: Uncased<'static> = uncased.into_owned();
assert_eq!(owned, "foo");
source

pub fn into_string(self) -> String

Converts self into an owned String, allocating if necessary.

§Example
use uncased::Uncased;

let uncased = Uncased::new("Content-Type");
let string = uncased.into_string();
assert_eq!(string, "Content-Type".to_string());
source

pub fn into_owned(self) -> Uncased<'static>

Converts self into an owned Uncased<'static>, allocating if necessary.

§Example
use uncased::Uncased;

let foo = "foo".to_string();
let uncased = Uncased::from(foo.as_str());
let owned: Uncased<'static> = uncased.into_owned();
assert_eq!(owned, "foo");
source

pub fn into_boxed_uncased(self) -> Box<UncasedStr>

Converts self into a Box<UncasedStr>.

§Example
use uncased::Uncased;

let boxed = Uncased::new("Content-Type").into_boxed_uncased();
assert_eq!(&*boxed, "content-type");

Methods from Deref<Target = UncasedStr>§

source

pub fn as_str(&self) -> &str

Returns self as an &str.

§Example
use uncased::UncasedStr;

let uncased_str = UncasedStr::new("Hello!");
assert_eq!(uncased_str.as_str(), "Hello!");
assert_ne!(uncased_str.as_str(), "hELLo!");
source

pub fn len(&self) -> usize

Returns the length, in bytes, of self.

§Example
use uncased::UncasedStr;

let uncased_str = UncasedStr::new("Hello!");
assert_eq!(uncased_str.len(), 6);
source

pub fn is_empty(&self) -> bool

Returns true if self has a length of zero bytes.

§Examples
use uncased::UncasedStr;

let s = UncasedStr::new("");
assert!(s.is_empty());

let s = UncasedStr::new("not empty");
assert!(!s.is_empty());
source

pub fn starts_with(&self, string: &str) -> bool

Returns true if self starts with any casing of the string string; otherwise, returns false.

§Example
use uncased::UncasedStr;

let uncased_str = UncasedStr::new("MoOO");
assert!(uncased_str.starts_with("moo"));
assert!(uncased_str.starts_with("MOO"));
assert!(uncased_str.starts_with("MOOO"));
assert!(!uncased_str.starts_with("boo"));

let uncased_str = UncasedStr::new("Bèe");
assert!(!uncased_str.starts_with("Be"));
assert!(uncased_str.starts_with("Bè"));
assert!(uncased_str.starts_with("Bè"));
assert!(uncased_str.starts_with("bèe"));
assert!(uncased_str.starts_with("BèE"));

Trait Implementations§

source§

impl AsRef<[u8]> for Uncased<'_>

source§

fn as_ref(&self) -> &[u8]

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

impl AsRef<UncasedStr> for Uncased<'_>

source§

fn as_ref(&self) -> &UncasedStr

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

impl AsRef<str> for Uncased<'_>

source§

fn as_ref(&self) -> &str

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

impl Borrow<UncasedStr> for Uncased<'_>

source§

fn borrow(&self) -> &UncasedStr

Immutably borrows from an owned value. Read more
source§

impl<'s> Clone for Uncased<'s>

source§

fn clone(&self) -> Uncased<'s>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'s> Debug for Uncased<'s>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for Uncased<'_>

§

type Target = UncasedStr

The resulting type after dereferencing.
source§

fn deref(&self) -> &UncasedStr

Dereferences the value.
source§

impl Display for Uncased<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'s, 'c: 's> From<&'c UncasedStr> for Uncased<'s>

source§

fn from(string: &'c UncasedStr) -> Self

Converts to this type from the input type.
source§

impl<'s, 'c: 's> From<&'c str> for Uncased<'s>

source§

fn from(string: &'c str) -> Self

Converts to this type from the input type.
source§

impl<'s, 'c: 's> From<Cow<'c, str>> for Uncased<'s>

source§

fn from(string: Cow<'c, str>) -> Self

Converts to this type from the input type.
source§

impl From<String> for Uncased<'static>

source§

fn from(string: String) -> Self

Converts to this type from the input type.
source§

impl Hash for Uncased<'_>

source§

fn hash<H: Hasher>(&self, hasher: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Ord for Uncased<'_>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<&Uncased<'_>> for String

source§

fn eq(&self, other: &&Uncased<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq<&str> for Uncased<'_>

source§

fn eq(&self, other: &&str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq<String> for &Uncased<'_>

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq<String> for Uncased<'_>

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq<Uncased<'_>> for &str

source§

fn eq(&self, other: &Uncased<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq<Uncased<'_>> for String

source§

fn eq(&self, other: &Uncased<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq<Uncased<'_>> for Uncased<'_>

source§

fn eq(&self, other: &Uncased<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq<Uncased<'_>> for str

source§

fn eq(&self, other: &Uncased<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialEq<str> for Uncased<'_>

source§

fn eq(&self, other: &str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialOrd<&Uncased<'_>> for String

source§

fn partial_cmp(&self, other: &&Uncased<'_>) -> Option<Ordering>

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

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl PartialOrd<String> for &Uncased<'_>

source§

fn partial_cmp(&self, other: &String) -> Option<Ordering>

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

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl PartialOrd<String> for Uncased<'_>

source§

fn partial_cmp(&self, other: &String) -> Option<Ordering>

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

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl PartialOrd<Uncased<'_>> for String

source§

fn partial_cmp(&self, other: &Uncased<'_>) -> Option<Ordering>

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

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl PartialOrd<Uncased<'_>> for Uncased<'_>

source§

fn partial_cmp(&self, other: &Uncased<'_>) -> Option<Ordering>

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

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl PartialOrd<Uncased<'_>> for str

source§

fn partial_cmp(&self, other: &Uncased<'_>) -> Option<Ordering>

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

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl PartialOrd<str> for Uncased<'_>

source§

fn partial_cmp(&self, other: &str) -> Option<Ordering>

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

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl Eq for Uncased<'_>

Auto Trait Implementations§

§

impl<'s> Freeze for Uncased<'s>

§

impl<'s> RefUnwindSafe for Uncased<'s>

§

impl<'s> Send for Uncased<'s>

§

impl<'s> Sync for Uncased<'s>

§

impl<'s> Unpin for Uncased<'s>

§

impl<'s> UnwindSafe for Uncased<'s>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsUncased for T
where T: AsRef<str> + ?Sized,

source§

fn as_uncased(&self) -> &UncasedStr

Convert self to an UncasedStr.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.