Struct rocket_http::uncased::UncasedStr
source · pub struct UncasedStr(_);
Expand description
A cost-free reference to an uncased (case-insensitive, case-preserving) ASCII string.
This is typically created from an &str
as follows:
use uncased::UncasedStr;
let ascii_ref: &UncasedStr = "Hello, world!".into();
Implementations§
source§impl UncasedStr
impl UncasedStr
sourcepub const fn new(string: &str) -> &UncasedStr
pub const fn new(string: &str) -> &UncasedStr
Cost-free conversion from an &str
reference to an UncasedStr
.
This is a const fn
on Rust 1.56+.
Example
use uncased::UncasedStr;
let uncased_str = UncasedStr::new("Hello!");
assert_eq!(uncased_str, "hello!");
assert_eq!(uncased_str, "Hello!");
assert_eq!(uncased_str, "HeLLo!");
sourcepub fn as_str(&self) -> &str
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!");
sourcepub fn len(&self) -> usize
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);
sourcepub fn is_empty(&self) -> bool
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());
sourcepub fn starts_with(&self, string: &str) -> bool
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"));
sourcepub fn into_uncased(self: Box<UncasedStr, Global>) -> Uncased<'static>
Available on crate feature alloc
only.
pub fn into_uncased(self: Box<UncasedStr, Global>) -> Uncased<'static>
alloc
only.Converts a Box<UncasedStr>
into an Uncased
without copying or
allocating.
Example
use uncased::Uncased;
let uncased = Uncased::new("Hello!");
let boxed = uncased.clone().into_boxed_uncased();
assert_eq!(boxed.into_uncased(), uncased);
Trait Implementations§
source§impl AsRef<[u8]> for UncasedStr
impl AsRef<[u8]> for UncasedStr
source§impl AsRef<UncasedStr> for Uncased<'_>
impl AsRef<UncasedStr> for Uncased<'_>
source§fn as_ref(&self) -> &UncasedStr
fn as_ref(&self) -> &UncasedStr
Converts this type into a shared reference of the (usually inferred) input type.
source§impl AsRef<str> for UncasedStr
impl AsRef<str> for UncasedStr
source§impl Borrow<UncasedStr> for Uncased<'_>
impl Borrow<UncasedStr> for Uncased<'_>
source§fn borrow(&self) -> &UncasedStr
fn borrow(&self) -> &UncasedStr
Immutably borrows from an owned value. Read more
source§impl Debug for UncasedStr
impl Debug for UncasedStr
source§impl Display for UncasedStr
impl Display for UncasedStr
source§impl<'a> From<&'a str> for &'a UncasedStr
impl<'a> From<&'a str> for &'a UncasedStr
source§fn from(string: &'a str) -> &'a UncasedStr
fn from(string: &'a str) -> &'a UncasedStr
Converts to this type from the input type.
source§impl<'s, 'c> From<&'c UncasedStr> for Uncased<'s>where
'c: 's,
impl<'s, 'c> From<&'c UncasedStr> for Uncased<'s>where 'c: 's,
source§fn from(string: &'c UncasedStr) -> Uncased<'s>
fn from(string: &'c UncasedStr) -> Uncased<'s>
Converts to this type from the input type.
source§impl Hash for UncasedStr
impl Hash for UncasedStr
source§impl<I> Index<I> for UncasedStrwhere
I: SliceIndex<str, Output = str>,
impl<I> Index<I> for UncasedStrwhere I: SliceIndex<str, Output = str>,
§type Output = UncasedStr
type Output = UncasedStr
The returned type after indexing.
source§impl Ord for UncasedStr
impl Ord for UncasedStr
source§impl PartialEq<&UncasedStr> for str
impl PartialEq<&UncasedStr> for str
source§fn eq(&self, other: &&UncasedStr) -> bool
fn eq(&self, other: &&UncasedStr) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<&str> for UncasedStr
impl PartialEq<&str> for UncasedStr
source§impl PartialEq<String> for UncasedStr
impl PartialEq<String> for UncasedStr
source§impl PartialEq<UncasedStr> for &str
impl PartialEq<UncasedStr> for &str
source§fn eq(&self, other: &UncasedStr) -> bool
fn eq(&self, other: &UncasedStr) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<UncasedStr> for UncasedStr
impl PartialEq<UncasedStr> for UncasedStr
source§fn eq(&self, other: &UncasedStr) -> bool
fn eq(&self, other: &UncasedStr) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<UncasedStr> for str
impl PartialEq<UncasedStr> for str
source§fn eq(&self, other: &UncasedStr) -> bool
fn eq(&self, other: &UncasedStr) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<str> for &UncasedStr
impl PartialEq<str> for &UncasedStr
source§impl PartialEq<str> for UncasedStr
impl PartialEq<str> for UncasedStr
source§impl PartialOrd<String> for UncasedStr
impl PartialOrd<String> for UncasedStr
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 moresource§impl PartialOrd<UncasedStr> for UncasedStr
impl PartialOrd<UncasedStr> for UncasedStr
source§fn partial_cmp(&self, other: &UncasedStr) -> Option<Ordering>
fn partial_cmp(&self, other: &UncasedStr) -> Option<Ordering>
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 moresource§impl PartialOrd<UncasedStr> for str
impl PartialOrd<UncasedStr> for str
source§fn partial_cmp(&self, other: &UncasedStr) -> Option<Ordering>
fn partial_cmp(&self, other: &UncasedStr) -> Option<Ordering>
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 moresource§impl PartialOrd<str> for UncasedStr
impl PartialOrd<str> for UncasedStr
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 moreimpl Eq for UncasedStr
Auto Trait Implementations§
impl RefUnwindSafe for UncasedStr
impl Send for UncasedStr
impl !Sized for UncasedStr
impl Sync for UncasedStr
impl Unpin for UncasedStr
impl UnwindSafe for UncasedStr
Blanket Implementations§
source§impl<T> AsUncased for Twhere
T: AsRef<str> + ?Sized,
impl<T> AsUncased for Twhere T: AsRef<str> + ?Sized,
source§fn as_uncased(&self) -> &UncasedStr
fn as_uncased(&self) -> &UncasedStr
Convert
self
to an UncasedStr
.