Struct spider::CaseInsensitiveString

source ·
pub struct CaseInsensitiveString(/* private fields */);
Expand description

case-insensitive string handling

Implementations§

source§

impl CaseInsensitiveString

source

pub fn new<'a, B>(bytes: &'a B) -> CaseInsensitiveString
where B: AsRef<[u8]> + ?Sized,

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);
source

pub fn as_bytes(&self) -> &[u8]

source

pub fn inner(&self) -> &CompactString

source

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!(CaseInsensitiveString::from("foobar"), s);
source

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!(CaseInsensitiveString::new("abc123"), s);
source

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".into());

assert_eq!(c.remove(5), 'w');
assert_eq!(c, "ello orld".into());
§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);
source

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);
source

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

source§

fn as_ref(&self) -> &str

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

impl Clone for CaseInsensitiveString

source§

fn clone(&self) -> CaseInsensitiveString

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 Debug for CaseInsensitiveString

source§

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

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

impl Default for CaseInsensitiveString

source§

fn default() -> CaseInsensitiveString

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for CaseInsensitiveString

source§

fn deserialize<D>( deserializer: D ) -> Result<CaseInsensitiveString, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<&[u8]> for CaseInsensitiveString

source§

fn from(s: &[u8]) -> CaseInsensitiveString

Converts to this type from the input type.
source§

impl From<&str> for CaseInsensitiveString

source§

fn from(s: &str) -> CaseInsensitiveString

Converts to this type from the input type.
source§

impl From<CompactString> for CaseInsensitiveString

source§

fn from(s: CompactString) -> CaseInsensitiveString

Converts to this type from the input type.
source§

impl From<String> for CaseInsensitiveString

source§

fn from(s: String) -> CaseInsensitiveString

Converts to this type from the input type.
source§

impl Hash for CaseInsensitiveString

source§

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

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 PartialEq for CaseInsensitiveString

source§

fn eq(&self, other: &CaseInsensitiveString) -> 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 Serialize for CaseInsensitiveString

source§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for CaseInsensitiveString

Auto Trait Implementations§

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> 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,