Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

§Meta Storage(CAS)

In-memory CAS (content addressed storage) for Rain metadata which basically stores k/v pairs of meta hash and meta bytes, as well as providing functionalities to easliy read/write to the CAS.

Hashes are normal bytes and meta bytes are valid cbor encoded as data bytes.

§Examples

use rain_metadata::Store;
use rain_metadata::meta::cache::MetaCache;
use std::collections::HashMap;

// to instantiate with an empty subgraph list
let mut store = Store::new();

// or to instantiate with initial values
let mut store = Store::create(
    &vec!["sg-url-1".to_string()],
    &MetaCache::default(),
    &HashMap::new(),
);

// add a new subgraph endpoint url to the subgraph list
store.add_subgraphs(&vec!["sg-url-2".to_string()]);

// merge another Store into this one
store.merge(&Store::new());

// updates the meta store with some bytes and the hash they hash to - a
// pair that does not is refused, so the hash is derived rather than picked
let bytes = vec![0u8, 1u8];
let hash = alloy::primitives::keccak256(&bytes).0.to_vec();
store.update_with(&hash, &bytes).unwrap();

// `Store::update(&hash)` is async; it searches each subgraph for `hash` and
// populates the cache with the result. Call it from an async context with `.await`.

// to get a record from the store
let _meta = store.get_meta(&hash);

// Store is agnostic to dotrain contents — it just maps the hash of the content
// to the given uri and puts it as a new meta into the meta cache.
let dotrain_uri = "path/to/file.rain";
let dotrain_content = "/* some dotrain source */";
let (_new_hash, _old_hash) = store
    .set_dotrain(dotrain_content, dotrain_uri, false)
    .unwrap();

// to get dotrain meta bytes given a uri
let _dotrain_meta_bytes = store.get_dotrain_meta(dotrain_uri);

Implementations§

Source§

impl Store

Source

pub fn new() -> Store

lazily creates a new instance with no subgraphs it is recommended to use create() instead with initial values

Source

pub fn create( subgraphs: &Vec<String>, cache: &MetaCache, dotrain_cache: &HashMap<String, Vec<u8>>, ) -> Store

creates new instance of Store with given initial values it checks the validity of each item of the provided values and only stores those that are valid

Source

pub fn subgraphs(&self) -> &Vec<String>

all subgraph endpoints in this instance

Source

pub fn add_subgraphs(&mut self, subgraphs: &Vec<String>)

add new subgraph endpoints

Source

pub fn cache(&self) -> &MetaCache

getter method for the whole meta cache

Source

pub fn get_meta(&self, hash: &[u8]) -> Option<&Vec<u8>>

get the corresponding meta bytes of the given hash if it exists

Source

pub fn dotrain_cache(&self) -> &HashMap<String, Vec<u8>>

getter method for the whole dotrain cache

Source

pub fn get_dotrain_hash(&self, uri: &str) -> Option<&Vec<u8>>

get the corresponding dotrain hash of the given dotrain uri if it exists

Source

pub fn get_dotrain_uri(&self, hash: &[u8]) -> Option<&String>

get the corresponding uri of the given dotrain hash if it exists

Source

pub fn get_dotrain_meta(&self, uri: &str) -> Option<&Vec<u8>>

get the corresponding meta bytes of the given dotrain uri if it exists

Source

pub fn delete_dotrain(&mut self, uri: &str, keep_meta: bool)

deletes a dotrain record given a uri, keep_meta = false drops the meta bytes only when no other dotrain uri still maps to them

Source

pub fn merge(&mut self, other: &Store)

lazilly merges another Store to the current one, avoids duplicates every map keeps the entry this Store already has on a key collision

Source

pub async fn update(&mut self, hash: &[u8]) -> Result<&Vec<u8>, Error>

updates the meta cache by searching through all subgraphs for the given hash, and returns the reference to the meta bytes in the cache if it was found. Refreshes unconditionally; Self::update_check is the variant that leaves an already cached hash alone.

Source

pub async fn update_check(&mut self, hash: &[u8]) -> Result<&Vec<u8>, Error>

first checks if the meta is stored, if not will perform update()

Source

pub fn update_with( &mut self, hash: &[u8], bytes: &[u8], ) -> Result<&Vec<u8>, Error>

updates the meta cache with the given hash and meta bytes, and returns the reference to the bytes if they were accepted. Leaves an already cached hash alone, as Self::update_check does for the subgraph path.

Source

pub fn set_dotrain( &mut self, text: &str, uri: &str, keep_old: bool, ) -> Result<(Vec<u8>, Vec<u8>), Error>

stores (or updates in case the URI already exists) the given dotrain text as meta into the store cache and maps it to the given uri (path), it should be noted that reading the content of the dotrain is not in the scope of Store and handling and passing on a correct URI (path) for the given text must be handled externally by the implementer, keep_old = false drops the replaced meta bytes only when no other dotrain uri still maps to them

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Store

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Store

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Store

Source§

fn eq(&self, other: &Store) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Store

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Store

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<'de, T> BorrowedRpcObject<'de> for T
where T: RpcBorrow<'de> + RpcSend,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IsFieldType<T> for T

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<'de, T> RpcBorrow<'de> for T
where T: Deserialize<'de> + Debug + Send + Sync + Unpin,

Source§

impl<T> RpcObject for T
where T: RpcSend + RpcRecv,

Source§

impl<T> RpcRecv for T
where T: DeserializeOwned + Debug + Send + Sync + Unpin + 'static,

Source§

impl<T> RpcSend for T
where T: Serialize + Clone + Debug + Send + Sync + Unpin,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more