#[repr(transparent)]
pub struct SetSubSlice<K: AsRef<str>>(_);
Expand description

A subslice of a PrefixArraySet in which all items contain a common prefix (which may be the unit prefix "").

The SetSubSlice does not store what that common prefix is for performance reasons (but it can be computed, see: SetSubSlice::common_prefix), it is up to the user to keep track of.

Implementations§

source§

impl<K: AsRef<str>> SetSubSlice<K>

source

pub fn iter(&self) -> Iter<'_, K>

Returns an iterator over all of the elements of this SetSubSlice

source

pub fn to_vec(&self) -> Vec<K>where K: Clone,

Creates an owned copy of this SetSubSlice as a Vec. If you wish to preserve PrefixArraySet semantics consider using ToOwned instead.

source

pub fn find_all_with_prefix<'a>(&'a self, prefix: &str) -> &'a Self

Returns the SetSubSlice where all K have the same prefix prefix.

Will return an empty array if there are no matches.

This operation is O(log n)

Examples
let set = PrefixArraySet::from_iter(["foo", "bar", "baz"]);

assert_eq!(set.find_all_with_prefix("b").to_vec(), vec!["bar", "baz"]);
source

pub fn common_prefix(&self) -> &str

Compute the common prefix of this SetSubSlice from the data. Will return an empty string if this subslice is empty.

Note that this may be more specific than what was searched for, i/e:

let arr = PrefixArraySet::from_iter(["12346", "12345", "12341"]);
// Common prefix is *computed*, so even though we only
//  searched for "12" we got something more specific
assert_eq!(arr.find_all_with_prefix("12").common_prefix(), "1234");

This operation is O(1), but it is not computationally free.

source

pub fn contains(&self, key: &str) -> bool

Returns whether this SetSubSlice contains the given key

This operation is O(log n).

source

pub const fn is_empty(&self) -> bool

Returns whether this SetSubSlice is empty

source

pub const fn len(&self) -> usize

Returns the length of this SetSubSlice

Trait Implementations§

source§

impl<K: AsRef<str>> Borrow<SetSubSlice<K>> for PrefixArraySet<K>

source§

fn borrow(&self) -> &SetSubSlice<K>

Immutably borrows from an owned value. Read more
source§

impl<K: AsRef<str> + Debug> Debug for SetSubSlice<K>

source§

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

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

impl<'a, K: AsRef<str>> IntoIterator for &'a SetSubSlice<K>

§

type Item = &'a K

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, K>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K: PartialEq + AsRef<str>> PartialEq<SetSubSlice<K>> for SetSubSlice<K>

source§

fn eq(&self, other: &SetSubSlice<K>) -> 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<K: AsRef<str> + Clone> ToOwned for SetSubSlice<K>

§

type Owned = PrefixArraySet<K>

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> PrefixArraySet<K>

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut PrefixArraySet<K>)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<K: Eq + AsRef<str>> Eq for SetSubSlice<K>

source§

impl<K: AsRef<str>> StructuralEq for SetSubSlice<K>

source§

impl<K: AsRef<str>> StructuralPartialEq for SetSubSlice<K>

Auto Trait Implementations§

§

impl<K> RefUnwindSafe for SetSubSlice<K>where K: RefUnwindSafe,

§

impl<K> Send for SetSubSlice<K>where K: Send,

§

impl<K> !Sized for SetSubSlice<K>

§

impl<K> Sync for SetSubSlice<K>where K: Sync,

§

impl<K> Unpin for SetSubSlice<K>where K: Unpin,

§

impl<K> UnwindSafe for SetSubSlice<K>where K: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more