Struct zerotrie::cursor::ZeroAsciiIgnoreCaseTrieCursor

source ·
pub struct ZeroAsciiIgnoreCaseTrieCursor<'a> {
    trie: ZeroAsciiIgnoreCaseTrie<&'a [u8]>,
}
Expand description

A cursor into a ZeroAsciiIgnoreCaseTrie, useful for stepwise lookup.

For examples, see ZeroAsciiIgnoreCaseTrie::cursor().

Fields§

§trie: ZeroAsciiIgnoreCaseTrie<&'a [u8]>

Implementations§

source§

impl<'a> ZeroAsciiIgnoreCaseTrieCursor<'a>

source

pub fn step(&mut self, byte: u8) -> Option<u8>

Steps the cursor one byte into the trie.

Returns the byte if matched, which may be a different case than the input byte. If this function returns None, any lookup loops can be terminated.

§Examples

Normalize the case of a value by stepping through an ignore-case trie:

use std::borrow::Cow;
use zerotrie::ZeroAsciiIgnoreCaseTrie;

// A trie with two values: "aBc" and "aBcdEf"
let trie = ZeroAsciiIgnoreCaseTrie::from_bytes(b"aBc\x80dEf\x81");

// Get out the value for "abc" and normalize the key string
let mut cursor = trie.cursor();
let mut key_str = Cow::Borrowed("abc".as_bytes());
let mut i = 0;
let value = loop {
    let Some(&input_byte) = key_str.get(i) else {
        break cursor.take_value();
    };
    let Some(matched_byte) = cursor.step(input_byte) else {
        break None;
    };
    if matched_byte != input_byte {
        key_str.to_mut()[i] = matched_byte;
    }
    i += 1;
};

assert_eq!(value, Some(0));
assert_eq!(&*key_str, "aBc".as_bytes());

For more examples, see ZeroTrieSimpleAsciiCursor::step.

source

pub fn take_value(&mut self) -> Option<usize>

Takes the value at the current position.

For more details, see ZeroTrieSimpleAsciiCursor::take_value.

source

pub fn probe(&mut self, index: usize) -> Option<AsciiProbeResult>

Probes the next byte in the cursor.

For more details, see ZeroTrieSimpleAsciiCursor::probe.

source

pub fn is_empty(&self) -> bool

Checks whether the cursor points to an empty trie.

For more details, see ZeroTrieSimpleAsciiCursor::is_empty.

Trait Implementations§

source§

impl<'a> Clone for ZeroAsciiIgnoreCaseTrieCursor<'a>

source§

fn clone(&self) -> ZeroAsciiIgnoreCaseTrieCursor<'a>

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<'a> Debug for ZeroAsciiIgnoreCaseTrieCursor<'a>

source§

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

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

impl<'a> Write for ZeroAsciiIgnoreCaseTrieCursor<'a>

source§

fn write_str(&mut self, s: &str) -> Result

Steps the cursor through each ASCII byte of the string.

If the string contains non-ASCII chars, an error is returned.

source§

fn write_char(&mut self, c: char) -> Result

Equivalent to ZeroAsciiIgnoreCaseTrieCursor::step(), except returns an error if the char is non-ASCII.

1.0.0 · source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more

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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ErasedDestructor for T
where T: 'static,