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<IK, T, PK> UniqueIndex<'_, IK, T, PK>
impl<IK, T, PK> UniqueIndex<'_, IK, T, PK>
Sourcepub const fn new(idx_fn: fn(&T) -> IK, idx_namespace: &'static str) -> Self
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>
impl<'a, IK, T, PK> UniqueIndex<'a, IK, T, PK>
Source§impl<'a, IK, T, PK> UniqueIndex<'a, IK, T, PK>
impl<'a, IK, T, PK> UniqueIndex<'a, IK, T, PK>
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,
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>where
PK: PrimaryKey<'a> + KeyDeserialize,
T: Serialize + DeserializeOwned + Clone,
IK: PrimaryKey<'a>,
impl<'a, IK, T, PK> UniqueIndex<'a, IK, T, PK>where
PK: PrimaryKey<'a> + KeyDeserialize,
T: Serialize + DeserializeOwned + Clone,
IK: PrimaryKey<'a>,
Sourcepub 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,
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.
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,
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,
pub fn prefix(&self, p: IK::Prefix) -> IndexPrefix<PK, T, IK::Suffix>
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>
impl<'a, IK, T, PK> Index<T> for UniqueIndex<'a, IK, T, PK>
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>
impl<'a, IK, T, PK> Sync for UniqueIndex<'a, IK, T, PK>
impl<'a, IK, T, PK> Unpin for UniqueIndex<'a, IK, T, PK>
impl<'a, IK, T, PK> UnwindSafe for UniqueIndex<'a, IK, T, PK>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more