pub struct UncasedStr(/* private fields */);
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>) -> Uncased<'static>
Available on crate feature alloc
only.
pub fn into_uncased(self: Box<UncasedStr>) -> 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
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
Source§impl Debug for UncasedStr
impl Debug for UncasedStr
Source§impl<'a, 'de> Deserialize<'de> for &'a UncasedStrwhere
'de: 'a,
impl<'a, 'de> Deserialize<'de> for &'a UncasedStrwhere
'de: 'a,
Source§fn deserialize<D>(
deserializer: D,
) -> Result<&'a UncasedStr, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<&'a UncasedStr, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Display for UncasedStr
impl Display for UncasedStr
Source§impl From<&UncasedStr> for Arc<UncasedStr>
impl From<&UncasedStr> for Arc<UncasedStr>
Source§fn from(v: &UncasedStr) -> Arc<UncasedStr>
fn from(v: &UncasedStr) -> Arc<UncasedStr>
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>
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
Source§impl Hash for UncasedStr
impl Hash for UncasedStr
Source§impl<I> Index<I> for UncasedStr
impl<I> Index<I> for UncasedStr
Source§impl Ord for UncasedStr
impl Ord for UncasedStr
Source§impl PartialEq<&Uncased<'_>> for UncasedStr
impl PartialEq<&Uncased<'_>> for UncasedStr
Source§impl PartialEq<&UncasedStr> for Uncased<'_>
impl PartialEq<&UncasedStr> for Uncased<'_>
Source§impl PartialEq<&UncasedStr> for str
impl PartialEq<&UncasedStr> for str
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<Uncased<'_>> for &UncasedStr
impl PartialEq<Uncased<'_>> for &UncasedStr
Source§impl PartialEq<Uncased<'_>> for UncasedStr
impl PartialEq<Uncased<'_>> for UncasedStr
Source§impl PartialEq<UncasedStr> for &Uncased<'_>
impl PartialEq<UncasedStr> for &Uncased<'_>
Source§impl PartialEq<UncasedStr> for &str
impl PartialEq<UncasedStr> for &str
Source§impl PartialEq<UncasedStr> for String
impl PartialEq<UncasedStr> for String
Source§impl PartialEq<UncasedStr> for Uncased<'_>
impl PartialEq<UncasedStr> for Uncased<'_>
Source§impl PartialEq<UncasedStr> for str
impl PartialEq<UncasedStr> for str
Source§impl PartialEq<str> for &UncasedStr
impl PartialEq<str> for &UncasedStr
Source§impl PartialEq<str> for UncasedStr
impl PartialEq<str> for UncasedStr
Source§impl PartialEq for UncasedStr
impl PartialEq for UncasedStr
Source§impl PartialOrd<&Uncased<'_>> for UncasedStr
impl PartialOrd<&Uncased<'_>> for UncasedStr
Source§impl PartialOrd<&UncasedStr> for Uncased<'_>
impl PartialOrd<&UncasedStr> for Uncased<'_>
Source§impl PartialOrd<String> for UncasedStr
impl PartialOrd<String> for UncasedStr
Source§impl PartialOrd<Uncased<'_>> for &UncasedStr
impl PartialOrd<Uncased<'_>> for &UncasedStr
Source§impl PartialOrd<Uncased<'_>> for UncasedStr
impl PartialOrd<Uncased<'_>> for UncasedStr
Source§impl PartialOrd<UncasedStr> for &Uncased<'_>
impl PartialOrd<UncasedStr> for &Uncased<'_>
Source§impl PartialOrd<UncasedStr> for String
impl PartialOrd<UncasedStr> for String
Source§impl PartialOrd<UncasedStr> for Uncased<'_>
impl PartialOrd<UncasedStr> for Uncased<'_>
Source§impl PartialOrd<UncasedStr> for str
impl PartialOrd<UncasedStr> for str
Source§impl PartialOrd<str> for UncasedStr
impl PartialOrd<str> for UncasedStr
Source§impl PartialOrd for UncasedStr
impl PartialOrd for UncasedStr
Source§impl<'a> Serialize for &'a UncasedStr
impl<'a> Serialize for &'a UncasedStr
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl Eq for UncasedStr
Auto Trait Implementations§
impl Freeze for UncasedStr
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 T
impl<T> AsUncased for T
Source§fn as_uncased(&self) -> &UncasedStr
fn as_uncased(&self) -> &UncasedStr
self
to an UncasedStr
.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
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.bright_black());
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.bright_green());
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.bright_yellow());
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.bright_magenta());
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.bright_white());
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.on_bright_black());
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.on_bright_green());
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.on_bright_yellow());
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlue
.
§Example
println!("{}", value.on_bright_blue());
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.on_bright_magenta());
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightCyan
.
§Example
println!("{}", value.on_bright_cyan());
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.on_bright_white());
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::Underline
.
§Example
println!("{}", value.underline());
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::RapidBlink
.
§Example
println!("{}", value.rapid_blink());
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);