pub struct CaseInsensitiveString(/* private fields */);Expand description
case-insensitive string handling
Implementations§
source§impl CaseInsensitiveString
impl CaseInsensitiveString
sourcepub fn new<'a, B: ?Sized + AsRef<[u8]>>(bytes: &'a B) -> CaseInsensitiveString
pub fn new<'a, B: ?Sized + AsRef<[u8]>>(bytes: &'a B) -> CaseInsensitiveString
Creates a CaseInsensitiveString slice from any byte slice.
This is a cost-free conversion.
Example
You can create CaseInsensitiveString’s from byte arrays, byte slices or string slices:
use case_insensitive_string::CaseInsensitiveString;
let a = CaseInsensitiveString::new(b"abc");
let b = CaseInsensitiveString::new("abc");
assert_eq!(a, b);pub fn as_bytes(&self) -> &[u8] ⓘ
pub fn inner(&self) -> &String
sourcepub fn push(&mut self, ch: char)
pub fn push(&mut self, ch: char)
Appends the given char to the end of this CaseInsensitiveString.
Examples
let mut s = CaseInsensitiveString::new("foo");
s.push('b');
s.push('a');
s.push('r');
assert_eq!("foobar", s);sourcepub fn push_str(&mut self, s: &str)
pub fn push_str(&mut self, s: &str)
Appends a given string slice onto the end of this CaseInsensitiveString
Examples
let mut s = CaseInsensitiveString::new("abc");
s.push_str("123");
assert_eq!("abc123", s);sourcepub fn remove(&mut self, idx: usize) -> char
pub fn remove(&mut self, idx: usize) -> char
Removes a char from this CaseInsensitiveString at a byte position and returns it.
This is an O(n) operation, as it requires copying every element in the buffer.
Panics
Panics if idx is larger than or equal to the CaseInsensitiveString’s length,
or if it does not lie on a char boundary.
Examples
Basic usage:
let mut c = CaseInsensitiveString::from("hello world");
assert_eq!(c.remove(0), 'h');
assert_eq!(c, "ello world");
assert_eq!(c.remove(5), 'w');
assert_eq!(c, "ello orld");Past total length:
let mut c = CaseInsensitiveString::from("hello there!");
c.remove(100);Not on char boundary:
let mut c = CaseInsensitiveString::from("🦄");
c.remove(1);sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the CaseInsensitiveString in bytes, not chars or graphemes.
When using UTF-8 encoding (which all strings in Rust do) a single character will be 1 to 4
bytes long, therefore the return value of this method might not be what a human considers
the length of the string.
Examples
let ascii = CaseInsensitiveString::new("hello world");
assert_eq!(ascii.len(), 11);
let emoji = CaseInsensitiveString::new("👱");
assert_eq!(emoji.len(), 4);sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the CaseInsensitiveString has a length of 0, false otherwise
Examples
let mut msg = CaseInsensitiveString::new("");
assert!(msg.is_empty());
// add some characters
msg.push_str("hello reader!");
assert!(!msg.is_empty());Trait Implementations§
source§impl AsRef<str> for CaseInsensitiveString
impl AsRef<str> for CaseInsensitiveString
source§impl Clone for CaseInsensitiveString
impl Clone for CaseInsensitiveString
source§fn clone(&self) -> CaseInsensitiveString
fn clone(&self) -> CaseInsensitiveString
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more