pub struct MetaCache { /* private fields */ }Expand description
Meta bytes keyed by their own keccak256 hash.
The key is not a name for the bytes, it is a digest of them, and this type exists to make that true by construction rather than by discipline. The map is a BTreeMap so serializing twice gives the same bytes. std::collections::HashMap iterates in an order randomized per process, which would make a serialized cache unreproducible for no gain - every access here is by key.
Implementations§
Source§impl MetaCache
impl MetaCache
Sourcepub fn insert_verified(
&mut self,
hash: &[u8],
bytes: Vec<u8>,
) -> Result<&Vec<u8>, Error>
pub fn insert_verified( &mut self, hash: &[u8], bytes: Vec<u8>, ) -> Result<&Vec<u8>, Error>
Caches bytes under hash, and only if they hash to it.
A mismatch is Error::CorruptRecord rather than a miss: the responder answered a question about one hash with bytes that are another, which is not the same fact as the hash being absent. rainlanguage/rain.metadata#234 and #213 settled that distinction for the query layer; this is the same distinction at the cache.
Sourcepub fn contains_key(&self, hash: &[u8]) -> bool
pub fn contains_key(&self, hash: &[u8]) -> bool
Whether anything is cached under hash.
Sourcepub fn remove(&mut self, hash: &[u8])
pub fn remove(&mut self, hash: &[u8])
Drops whatever is cached under hash. Removing cannot break the
invariant, so it needs no check.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for MetaCache
Deserializing is a way into the cache, so it goes through the same gate.
impl<'de> Deserialize<'de> for MetaCache
Deserializing is a way into the cache, so it goes through the same gate.
A derived impl would build inner directly, which is how the invariant
leaked the first time this type was written: entries refused by
MetaCache::insert_verified were accepted wholesale off the wire. A cache
is only as good as the worst entry in it, so one bad pair rejects the whole
map rather than being dropped quietly - unlike a responder’s single answer,
a serialized cache is something this process wrote and should not be able
to get wrong.
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl StructuralPartialEq for MetaCache
Auto Trait Implementations§
impl Freeze for MetaCache
impl RefUnwindSafe for MetaCache
impl Send for MetaCache
impl Sync for MetaCache
impl Unpin for MetaCache
impl UnsafeUnpin for MetaCache
impl UnwindSafe for MetaCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<'de, T> BorrowedRpcObject<'de> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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