cnidarium

Trait StateRead

Source
pub trait StateRead: Send + Sync {
    type GetRawFut: Future<Output = Result<Option<Vec<u8>>>> + Send + 'static;
    type PrefixRawStream: Stream<Item = Result<(String, Vec<u8>)>> + Send + 'static;
    type PrefixKeysStream: Stream<Item = Result<String>> + Send + 'static;
    type NonconsensusPrefixRawStream: Stream<Item = Result<(Vec<u8>, Vec<u8>)>> + Send + 'static;
    type NonconsensusRangeRawStream: Stream<Item = Result<(Vec<u8>, Vec<u8>)>> + Send + 'static;

    // Required methods
    fn get_raw(&self, key: &str) -> Self::GetRawFut;
    fn nonverifiable_get_raw(&self, key: &[u8]) -> Self::GetRawFut;
    fn object_get<T: Any + Send + Sync + Clone>(
        &self,
        key: &'static str,
    ) -> Option<T>;
    fn object_type(&self, key: &'static str) -> Option<TypeId>;
    fn prefix_raw(&self, prefix: &str) -> Self::PrefixRawStream;
    fn prefix_keys(&self, prefix: &str) -> Self::PrefixKeysStream;
    fn nonverifiable_prefix_raw(
        &self,
        prefix: &[u8],
    ) -> Self::NonconsensusPrefixRawStream;
    fn nonverifiable_range_raw(
        &self,
        prefix: Option<&[u8]>,
        range: impl RangeBounds<Vec<u8>>,
    ) -> Result<Self::NonconsensusRangeRawStream>;
}
Expand description

Read access to chain state.

Required Associated Types§

Source

type GetRawFut: Future<Output = Result<Option<Vec<u8>>>> + Send + 'static

Source

type PrefixRawStream: Stream<Item = Result<(String, Vec<u8>)>> + Send + 'static

Source

type PrefixKeysStream: Stream<Item = Result<String>> + Send + 'static

Source

type NonconsensusPrefixRawStream: Stream<Item = Result<(Vec<u8>, Vec<u8>)>> + Send + 'static

Source

type NonconsensusRangeRawStream: Stream<Item = Result<(Vec<u8>, Vec<u8>)>> + Send + 'static

Required Methods§

Source

fn get_raw(&self, key: &str) -> Self::GetRawFut

Gets a value from the verifiable key-value store as raw bytes.

Users should generally prefer to use get or get_proto from an extension trait.

Source

fn nonverifiable_get_raw(&self, key: &[u8]) -> Self::GetRawFut

Gets a byte value from the non-verifiable key-value store.

This is intended for application-specific indexes of the verifiable consensus state, rather than for use as a primary data storage method.

Source

fn object_get<T: Any + Send + Sync + Clone>( &self, key: &'static str, ) -> Option<T>

Gets an object from the ephemeral key-object store.

This is intended to allow application components to build up batched data transactionally, ensuring that a transaction’s contributions to some batched data are only included if the entire transaction executed successfully. This data is not persisted to the Storage during commit.

§Returns
  • Some(&T) if a value of type T was present at key.
  • None if key was not present.
§Panics

If there is a value at key but it is not of the type requested.

Source

fn object_type(&self, key: &'static str) -> Option<TypeId>

Gets the [TypeId] of the object stored at key in the ephemeral key-object store, if any is present.

Source

fn prefix_raw(&self, prefix: &str) -> Self::PrefixRawStream

Retrieve all values for keys matching a prefix from the verifiable key-value store, as raw bytes.

Users should generally prefer to use prefix or prefix_proto from an extension trait.

Source

fn prefix_keys(&self, prefix: &str) -> Self::PrefixKeysStream

Retrieve all keys (but not values) matching a prefix from the verifiable key-value store.

Source

fn nonverifiable_prefix_raw( &self, prefix: &[u8], ) -> Self::NonconsensusPrefixRawStream

Retrieve all values for keys matching a prefix from the non-verifiable key-value store, as raw bytes.

Users should generally prefer to use wrapper methods in an extension trait.

Source

fn nonverifiable_range_raw( &self, prefix: Option<&[u8]>, range: impl RangeBounds<Vec<u8>>, ) -> Result<Self::NonconsensusRangeRawStream>

Retrieve all values for keys in a range from the non-verifiable key-value store, as raw bytes. This method does not support inclusive ranges, and will return an error if passed one.

Users should generally prefer to use wrapper methods in an extension trait.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl StateRead for ()

Source§

type GetRawFut = Ready<Result<Option<Vec<u8>>, Error>>

Source§

type PrefixRawStream = Iter<Empty<Result<(String, Vec<u8>), Error>>>

Source§

type PrefixKeysStream = Iter<Empty<Result<String, Error>>>

Source§

type NonconsensusPrefixRawStream = Iter<Empty<Result<(Vec<u8>, Vec<u8>), Error>>>

Source§

type NonconsensusRangeRawStream = Iter<Empty<Result<(Vec<u8>, Vec<u8>), Error>>>

Source§

fn get_raw(&self, _key: &str) -> Self::GetRawFut

Source§

fn nonverifiable_get_raw(&self, _key: &[u8]) -> Self::GetRawFut

Source§

fn object_get<T: Any + Send + Sync + Clone>( &self, _key: &'static str, ) -> Option<T>

Source§

fn object_type(&self, _key: &'static str) -> Option<TypeId>

Source§

fn prefix_raw(&self, _prefix: &str) -> Self::PrefixRawStream

Source§

fn prefix_keys(&self, _prefix: &str) -> Self::PrefixKeysStream

Source§

fn nonverifiable_prefix_raw( &self, _prefix: &[u8], ) -> Self::NonconsensusPrefixRawStream

Source§

fn nonverifiable_range_raw( &self, _prefix: Option<&[u8]>, _range: impl RangeBounds<Vec<u8>>, ) -> Result<Self::NonconsensusRangeRawStream>

Source§

impl<'a, S: StateRead + Send + Sync> StateRead for &'a S

Source§

impl<'a, S: StateRead + Send + Sync> StateRead for &'a mut S

Source§

impl<S: StateRead + Send + Sync> StateRead for Arc<S>

Implementors§