Trait levana_perpswap_cosmos::prelude::Storage
pub trait Storage {
// Required methods
fn get(&self, key: &[u8]) -> Option<Vec<u8>>;
fn set(&mut self, key: &[u8], value: &[u8]);
fn remove(&mut self, key: &[u8]);
// Provided methods
fn range<'a>(
&'a self,
start: Option<&[u8]>,
end: Option<&[u8]>,
order: Order,
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a> { ... }
fn range_keys<'a>(
&'a self,
start: Option<&[u8]>,
end: Option<&[u8]>,
order: Order,
) -> Box<dyn Iterator<Item = Vec<u8>> + 'a> { ... }
fn range_values<'a>(
&'a self,
start: Option<&[u8]>,
end: Option<&[u8]>,
order: Order,
) -> Box<dyn Iterator<Item = Vec<u8>> + 'a> { ... }
}Expand description
Storage provides read and write access to a persistent storage.
If you only want to provide read access, provide &Storage
Required Methods§
fn get(&self, key: &[u8]) -> Option<Vec<u8>>
fn get(&self, key: &[u8]) -> Option<Vec<u8>>
Returns None when key does not exist.
Returns Some(Vec
Note: Support for differentiating between a non-existent key and a key with empty value is not great yet and might not be possible in all backends. But we’re trying to get there.
fn set(&mut self, key: &[u8], value: &[u8])
Provided Methods§
fn range<'a>(
&'a self,
start: Option<&[u8]>,
end: Option<&[u8]>,
order: Order,
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>
fn range<'a>( &'a self, start: Option<&[u8]>, end: Option<&[u8]>, order: Order, ) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>
Allows iteration over a set of key/value pairs, either forwards or backwards.
The bound start is inclusive and end is exclusive.
If start is lexicographically greater than or equal to end, an empty range is described, mo matter of the order.
fn range_keys<'a>(
&'a self,
start: Option<&[u8]>,
end: Option<&[u8]>,
order: Order,
) -> Box<dyn Iterator<Item = Vec<u8>> + 'a>
fn range_keys<'a>( &'a self, start: Option<&[u8]>, end: Option<&[u8]>, order: Order, ) -> Box<dyn Iterator<Item = Vec<u8>> + 'a>
Allows iteration over a set of keys, either forwards or backwards.
The bound start is inclusive and end is exclusive.
If start is lexicographically greater than or equal to end, an empty range is described, mo matter of the order.
The default implementation uses Storage::range and discards the values. More efficient
implementations might be possible depending on the storage.
fn range_values<'a>(
&'a self,
start: Option<&[u8]>,
end: Option<&[u8]>,
order: Order,
) -> Box<dyn Iterator<Item = Vec<u8>> + 'a>
fn range_values<'a>( &'a self, start: Option<&[u8]>, end: Option<&[u8]>, order: Order, ) -> Box<dyn Iterator<Item = Vec<u8>> + 'a>
Allows iteration over a set of values, either forwards or backwards.
The bound start is inclusive and end is exclusive.
If start is lexicographically greater than or equal to end, an empty range is described, mo matter of the order.
The default implementation uses Storage::range and discards the keys. More efficient implementations
might be possible depending on the storage.