Struct fadroma::storage::SingleItem

source ·
pub struct SingleItem<T: FadromaSerialize + FadromaDeserialize, N: Namespace> { /* private fields */ }
Expand description

Storage type that stores a single item under the given Namespace. Use this when there is only “one of” something.

Examples

use fadroma::{
    cosmwasm_std::testing::mock_dependencies,
    storage::SingleItem
};
 
fadroma::namespace!(NumberNs, b"number");
const NUMBER: SingleItem::<u64, NumberNs> = SingleItem::new();
 
let mut deps = mock_dependencies();
let storage = deps.as_mut().storage;
 
NUMBER.save(storage, &13).unwrap();
 
let stored = NUMBER.load_or_default(storage).unwrap();
assert_eq!(stored, 13);
 

Implementations§

source§

impl<T: FadromaSerialize + FadromaDeserialize, N: Namespace> SingleItem<T, N>

source

pub const fn new() -> Self

source

pub fn namespace(&self) -> &'static [u8]

source

pub fn save(&self, storage: &mut dyn Storage, item: &T) -> StdResult<()>

source

pub fn load(&self, storage: &dyn Storage) -> StdResult<Option<T>>

source

pub fn load_or_error(&self, storage: &dyn Storage) -> StdResult<T>

source

pub fn remove(&self, storage: &mut dyn Storage)

source

pub fn canonize_and_save<Input: Canonize<Output = T>>( &self, deps: DepsMut<'_>, item: Input ) -> StdResult<()>

source§

impl<T: FadromaSerialize + FadromaDeserialize + Humanize, N: Namespace> SingleItem<T, N>

source

pub fn load_humanize( &self, deps: Deps<'_> ) -> StdResult<Option<<T as Humanize>::Output>>

source

pub fn load_humanize_or_error( &self, deps: Deps<'_> ) -> StdResult<<T as Humanize>::Output>

source§

impl<T: FadromaSerialize + FadromaDeserialize + Humanize, N: Namespace> SingleItem<T, N>where <T as Humanize>::Output: Default,

source

pub fn load_humanize_or_default( &self, deps: Deps<'_> ) -> StdResult<<T as Humanize>::Output>

source§

impl<T: FadromaSerialize + FadromaDeserialize + Default, N: Namespace> SingleItem<T, N>

source

pub fn load_or_default(&self, storage: &dyn Storage) -> StdResult<T>

Auto Trait Implementations§

§

impl<T, N> RefUnwindSafe for SingleItem<T, N>where N: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, N> Send for SingleItem<T, N>where N: Send, T: Send,

§

impl<T, N> Sync for SingleItem<T, N>where N: Sync, T: Sync,

§

impl<T, N> Unpin for SingleItem<T, N>where N: Unpin, T: Unpin,

§

impl<T, N> UnwindSafe for SingleItem<T, N>where N: UnwindSafe, T: 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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V