Struct levana_perpswap_cosmos::prelude::Map
pub struct Map<K, T> { /* private fields */ }Implementations§
§impl<K, T> Map<K, T>
impl<K, T> Map<K, T>
pub const fn new(namespace: &'static str) -> Map<K, T>
pub const fn new(namespace: &'static str) -> Map<K, T>
Creates a new Map with the given storage key. This is a const fn only suitable
when you have the storage key in the form of a static string slice.
pub fn namespace_bytes(&self) -> &[u8] ⓘ
§impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
pub fn key(&self, k: K) -> Path<T>
pub fn save( &self, store: &mut dyn Storage, k: K, data: &T, ) -> Result<(), StdError>
pub fn remove(&self, store: &mut dyn Storage, k: K)
pub fn load(&self, store: &dyn Storage, k: K) -> Result<T, StdError>
pub fn load(&self, store: &dyn Storage, k: K) -> Result<T, StdError>
load will return an error if no data is set at the given key, or on parse error
pub fn may_load(&self, store: &dyn Storage, k: K) -> Result<Option<T>, StdError>
pub fn may_load(&self, store: &dyn Storage, k: K) -> Result<Option<T>, StdError>
may_load will parse the data stored at the key if present, returns Ok(None) if no data there. returns an error on issues parsing
pub fn has(&self, store: &dyn Storage, k: K) -> bool
pub fn has(&self, store: &dyn Storage, k: K) -> bool
has returns true or false if any data is at this key, without parsing or interpreting the contents.
pub fn update<A, E>(
&self,
store: &mut dyn Storage,
k: K,
action: A,
) -> Result<T, E>
pub fn update<A, E>( &self, store: &mut dyn Storage, k: K, action: A, ) -> Result<T, E>
Loads the data, perform the specified action, and store the result in the database. This is shorthand for some common sequences, which may be useful.
If the data exists, action(Some(value)) is called. Otherwise action(None) is called.
§impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
pub fn sub_prefix( &self, p: <K as PrimaryKey<'a>>::SubPrefix, ) -> Prefix<<K as PrimaryKey<'a>>::SuperSuffix, T, <K as PrimaryKey<'a>>::SuperSuffix>
pub fn prefix( &self, p: <K as PrimaryKey<'a>>::Prefix, ) -> Prefix<<K as PrimaryKey<'a>>::Suffix, T, <K as PrimaryKey<'a>>::Suffix>
§impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
pub fn prefix_range_raw<'c>(
&self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, <K as PrimaryKey<'a>>::Prefix>>,
max: Option<PrefixBound<'a, <K as PrimaryKey<'a>>::Prefix>>,
order: Order,
) -> Box<dyn Iterator<Item = Result<(Vec<u8>, T), StdError>> + 'c>where
'a: 'c,
T: 'c,
pub fn prefix_range_raw<'c>(
&self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, <K as PrimaryKey<'a>>::Prefix>>,
max: Option<PrefixBound<'a, <K as PrimaryKey<'a>>::Prefix>>,
order: Order,
) -> Box<dyn Iterator<Item = Result<(Vec<u8>, T), StdError>> + 'c>where
'a: 'c,
T: 'c,
While range_raw over a prefix fixes the prefix to one element and iterates over the
remaining, prefix_range_raw 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.
§impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a> + KeyDeserialize,
impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a> + KeyDeserialize,
pub fn prefix_range<'c>(
&self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, <K as PrimaryKey<'a>>::Prefix>>,
max: Option<PrefixBound<'a, <K as PrimaryKey<'a>>::Prefix>>,
order: Order,
) -> Box<dyn Iterator<Item = Result<(<K as KeyDeserialize>::Output, T), StdError>> + 'c>where
'a: 'c,
T: 'c,
K: 'c,
<K as KeyDeserialize>::Output: 'static,
pub fn prefix_range<'c>(
&self,
store: &'c dyn Storage,
min: Option<PrefixBound<'a, <K as PrimaryKey<'a>>::Prefix>>,
max: Option<PrefixBound<'a, <K as PrimaryKey<'a>>::Prefix>>,
order: Order,
) -> Box<dyn Iterator<Item = Result<(<K as KeyDeserialize>::Output, T), StdError>> + 'c>where
'a: 'c,
T: 'c,
K: 'c,
<K as KeyDeserialize>::Output: 'static,
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.
§impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a>,
pub fn range_raw<'c>(
&self,
store: &'c dyn Storage,
min: Option<Bound<'a, K>>,
max: Option<Bound<'a, K>>,
order: Order,
) -> Box<dyn Iterator<Item = Result<(Vec<u8>, T), StdError>> + 'c>where
T: 'c,
pub fn keys_raw<'c>(
&self,
store: &'c dyn Storage,
min: Option<Bound<'a, K>>,
max: Option<Bound<'a, K>>,
order: Order,
) -> Box<dyn Iterator<Item = Vec<u8>> + 'c>where
T: 'c,
§impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a> + KeyDeserialize,
impl<'a, K, T> Map<K, T>where
T: Serialize + DeserializeOwned,
K: PrimaryKey<'a> + KeyDeserialize,
pub fn range<'c>(
&self,
store: &'c dyn Storage,
min: Option<Bound<'a, K>>,
max: Option<Bound<'a, K>>,
order: Order,
) -> Box<dyn Iterator<Item = Result<(<K as KeyDeserialize>::Output, T), StdError>> + 'c>where
T: 'c,
<K as KeyDeserialize>::Output: 'static,
pub fn keys<'c>(
&self,
store: &'c dyn Storage,
min: Option<Bound<'a, K>>,
max: Option<Bound<'a, K>>,
order: Order,
) -> Box<dyn Iterator<Item = Result<<K as KeyDeserialize>::Output, StdError>> + 'c>where
T: 'c,
<K as KeyDeserialize>::Output: 'static,
pub fn first(
&self,
storage: &dyn Storage,
) -> Result<Option<(<K as KeyDeserialize>::Output, T)>, StdError>where
<K as KeyDeserialize>::Output: 'static,
pub fn first(
&self,
storage: &dyn Storage,
) -> Result<Option<(<K as KeyDeserialize>::Output, T)>, StdError>where
<K as KeyDeserialize>::Output: 'static,
Returns the first key-value pair in the map. This is not according to insertion-order, but according to the key ordering.
§Examples
const MAP: Map<i32, u32> = Map::new("map");
// empty map
assert_eq!(MAP.first(&storage), Ok(None));
// insert entries
MAP.save(&mut storage, 1, &10).unwrap();
MAP.save(&mut storage, -2, &20).unwrap();
assert_eq!(MAP.first(&storage), Ok(Some((-2, 20))));pub fn last(
&self,
storage: &dyn Storage,
) -> Result<Option<(<K as KeyDeserialize>::Output, T)>, StdError>where
<K as KeyDeserialize>::Output: 'static,
pub fn last(
&self,
storage: &dyn Storage,
) -> Result<Option<(<K as KeyDeserialize>::Output, T)>, StdError>where
<K as KeyDeserialize>::Output: 'static,
Returns the last key-value pair in the map. This is not according to insertion-order, but according to the key ordering.
§Examples
const MAP: Map<i32, u32> = Map::new("map");
// empty map
assert_eq!(MAP.last(&storage), Ok(None));
// insert entries
MAP.save(&mut storage, 1, &10).unwrap();
MAP.save(&mut storage, -2, &20).unwrap();
assert_eq!(MAP.last(&storage), Ok(Some((1, 10))));Trait Implementations§
Auto Trait Implementations§
impl<K, T> Freeze for Map<K, T>
impl<K, T> RefUnwindSafe for Map<K, T>where
K: RefUnwindSafe,
T: RefUnwindSafe,
impl<K, T> Send for Map<K, T>
impl<K, T> Sync for Map<K, T>
impl<K, T> Unpin for Map<K, T>
impl<K, T> UnwindSafe for Map<K, T>where
K: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
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 moresource§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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)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>
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>
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