uncased/as_uncased.rs
1use crate::UncasedStr;
2
3/// Helper trait to convert string-like references to `&UncasedStr`.
4///
5/// # Example
6///
7/// ```rust
8/// use uncased::AsUncased;
9///
10/// let string = "Hello, world!".as_uncased();
11/// assert_eq!(string, "hello, world!");
12/// assert_eq!(string, "HELLO, world!");
13/// assert_eq!(string, "HELLO, WORLD!");
14/// ```
15pub trait AsUncased {
16 /// Convert `self` to an [`UncasedStr`].
17 fn as_uncased(&self) -> &UncasedStr;
18}
19
20impl<T: AsRef<str> + ?Sized> AsUncased for T {
21 #[inline(always)]
22 fn as_uncased(&self) -> &UncasedStr {
23 UncasedStr::new(self.as_ref())
24 }
25}