pub struct UniqueIndex<'a, IK, T, PK> { /* private fields */ }
Expand description

UniqueIndex stores (namespace, index_name, idx_value) -> {key, value} Allows one value per index (i.e. unique) and copies pk and data The PK type defines the type of Primary Key deserialization.

Implementations§

source§

impl<'a, IK, T, PK> UniqueIndex<'a, IK, T, PK>

source

pub const fn new(idx_fn: fn(_: &T) -> IK, idx_namespace: &'static str) -> Self

Create a new UniqueIndex

idx_fn - lambda creating index key from index value idx_namespace - prefix for the index value

§Example:
use cw_storage_plus::UniqueIndex;

struct Data {
    pub name: String,
    pub age: u32,
}

UniqueIndex::<_, _, ()>::new(|d: &Data| d.age, "data__age");
source§

impl<'a, IK, T, PK> UniqueIndex<'a, IK, T, PK>

source

pub fn index_key(&self, k: IK) -> Vec<u8>

source

pub fn item(&self, store: &dyn Storage, idx: IK) -> StdResult<Option<Record<T>>>

returns all items that match this secondary index, always by pk Ascending

source§

impl<'a, IK, T, PK> UniqueIndex<'a, IK, T, PK>

source

pub fn range_raw<'c>( &self, store: &'c dyn Storage, min: Option<Bound<'a, IK>>, max: Option<Bound<'a, IK>>, order: Order ) -> Box<dyn Iterator<Item = StdResult<Record<T>>> + 'c>
where T: 'c,

source

pub fn keys_raw<'c>( &self, store: &'c dyn Storage, min: Option<Bound<'a, IK>>, max: Option<Bound<'a, IK>>, order: Order ) -> Box<dyn Iterator<Item = Vec<u8>> + 'c>

source§

impl<'a, IK, T, PK> UniqueIndex<'a, IK, T, PK>

source

pub fn prefix_range<'c>( &self, store: &'c dyn Storage, min: Option<PrefixBound<'a, IK::Prefix>>, max: Option<PrefixBound<'a, IK::Prefix>>, order: Order ) -> Box<dyn Iterator<Item = StdResult<(PK::Output, T)>> + 'c>
where T: 'c, IK: 'c, PK: 'c, PK::Output: 'static, 'a: 'c,

While range over a prefix fixes the prefix to one element and iterates over the remaining, prefix_range accepts bounds for the lowest and highest elements of the Prefix itself, and iterates over those (inclusively or exclusively, depending on PrefixBound). There are some issues that distinguish these two, and blindly casting to Vec<u8> doesn’t solve them.

source

pub fn range<'c>( &self, store: &'c dyn Storage, min: Option<Bound<'a, IK>>, max: Option<Bound<'a, IK>>, order: Order ) -> Box<dyn Iterator<Item = StdResult<(PK::Output, T)>> + 'c>
where T: 'c, PK::Output: 'static,

source

pub fn keys<'c>( &self, store: &'c dyn Storage, min: Option<Bound<'a, IK>>, max: Option<Bound<'a, IK>>, order: Order ) -> Box<dyn Iterator<Item = StdResult<PK::Output>> + 'c>
where T: 'c, PK::Output: 'static,

source

pub fn prefix(&self, p: IK::Prefix) -> IndexPrefix<PK, T, IK::Suffix>

source

pub fn sub_prefix( &self, p: IK::SubPrefix ) -> IndexPrefix<PK, T, IK::SuperSuffix>

Trait Implementations§

source§

impl<'a, IK, T, PK> Index<T> for UniqueIndex<'a, IK, T, PK>

source§

fn save(&self, store: &mut dyn Storage, pk: &[u8], data: &T) -> StdResult<()>

source§

fn remove( &self, store: &mut dyn Storage, _pk: &[u8], old_data: &T ) -> StdResult<()>

Auto Trait Implementations§

§

impl<'a, IK, T, PK> Freeze for UniqueIndex<'a, IK, T, PK>

§

impl<'a, IK, T, PK> RefUnwindSafe for UniqueIndex<'a, IK, T, PK>

§

impl<'a, IK, T, PK> Send for UniqueIndex<'a, IK, T, PK>
where IK: Send, PK: Send, T: Send,

§

impl<'a, IK, T, PK> Sync for UniqueIndex<'a, IK, T, PK>
where IK: Sync, PK: Sync, T: Sync,

§

impl<'a, IK, T, PK> Unpin for UniqueIndex<'a, IK, T, PK>
where IK: Unpin, PK: Unpin, T: Unpin,

§

impl<'a, IK, T, PK> UnwindSafe for UniqueIndex<'a, IK, T, PK>
where IK: UnwindSafe, PK: UnwindSafe, T: UnwindSafe,

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<U> As for U

source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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> Same for T

§

type Output = T

Should always be Self
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.