Struct cw_storage_plus::Item
source · [−]pub struct Item<'a, T> { /* private fields */ }
Expand description
Item stores one typed item at the given key. This is an analog of Singleton. It functions the same way as Path does but doesn’t use a Vec and thus has a const fn constructor.
Implementations
sourceimpl<'a, T> Item<'a, T> where
T: Serialize + DeserializeOwned,
impl<'a, T> Item<'a, T> where
T: Serialize + DeserializeOwned,
pub fn as_slice(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
sourcepub fn save(&self, store: &mut dyn Storage, data: &T) -> StdResult<()>
pub fn save(&self, store: &mut dyn Storage, data: &T) -> StdResult<()>
save will serialize the model and store, returns an error on serialization issues
pub fn remove(&self, store: &mut dyn Storage)
sourcepub fn load(&self, store: &dyn Storage) -> StdResult<T>
pub fn load(&self, store: &dyn Storage) -> StdResult<T>
load will return an error if no data is set at the given key, or on parse error
sourcepub fn may_load(&self, store: &dyn Storage) -> StdResult<Option<T>>
pub fn may_load(&self, store: &dyn Storage) -> StdResult<Option<T>>
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
sourcepub fn update<A, E>(&self, store: &mut dyn Storage, action: A) -> Result<T, E> where
A: FnOnce(T) -> Result<T, E>,
E: From<StdError>,
pub fn update<A, E>(&self, store: &mut dyn Storage, action: A) -> Result<T, E> where
A: FnOnce(T) -> Result<T, E>,
E: From<StdError>,
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.
It assumes, that data was initialized before, and if it doesn’t exist, Err(StdError::NotFound)
is returned.
sourcepub fn query<Q: CustomQuery>(
&self,
querier: &QuerierWrapper<'_, Q>,
remote_contract: Addr
) -> StdResult<T>
pub fn query<Q: CustomQuery>(
&self,
querier: &QuerierWrapper<'_, Q>,
remote_contract: Addr
) -> StdResult<T>
If you import the proper Item from the remote contract, this will let you read the data from a remote contract in a type-safe way using WasmQuery::RawQuery.
Note that we expect an Item to be set, and error if there is no data there
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for Item<'a, T> where
T: RefUnwindSafe,
impl<'a, T> Send for Item<'a, T> where
T: Send,
impl<'a, T> Sync for Item<'a, T> where
T: Sync,
impl<'a, T> Unpin for Item<'a, T> where
T: Unpin,
impl<'a, T> UnwindSafe for Item<'a, T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more