Struct mz_persist_client::internal::encoding::LazyProto
source · pub struct LazyProto<T> {
buf: Bytes,
_phantom: PhantomData<fn() -> T>,
}
Expand description
A proto that is decoded on use.
Because of the way prost works, decoding a large protobuf may result in a number of very short lived allocations in our RustType/ProtoType decode path (e.g. this happens for a repeated embedded message). Not every use of persist State needs every transitive bit of it to be decoded, so we opt certain parts of it (initially stats) to be decoded on use.
This has the dual benefit of only paying for the short-lived allocs when necessary and also allowing decoding to be gated by a feature flag. The tradeoffs are that we might decode more than once and that we have to handle invalid proto errors in more places.
Mechanically, this is accomplished by making the field a proto bytes
types
instead of ProtoFoo
. These bytes then contain the serialization of
ProtoFoo. NB: Swapping between the two is actually a forward and backward
compatible change.
Embedded messages are compatible with bytes if the bytes contain an encoded version of the message.
(See https://protobuf.dev/programming-guides/proto3/#updating)
Fields§
§buf: Bytes
§_phantom: PhantomData<fn() -> T>
Implementations§
Trait Implementations§
source§impl<'de, T> Deserialize<'de> for LazyProto<T>
impl<'de, T> Deserialize<'de> for LazyProto<T>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<T> Ord for LazyProto<T>
impl<T> Ord for LazyProto<T>
source§impl<T> PartialOrd for LazyProto<T>
impl<T> PartialOrd for LazyProto<T>
source§impl<T: Message + Default> RustType<Bytes> for LazyProto<T>
impl<T: Message + Default> RustType<Bytes> for LazyProto<T>
source§fn into_proto(&self) -> Bytes
fn into_proto(&self) -> Bytes
Self
into a Proto
value.source§fn from_proto(buf: Bytes) -> Result<Self, TryFromProtoError>
fn from_proto(buf: Bytes) -> Result<Self, TryFromProtoError>
source§fn into_proto_owned(self) -> Proto
fn into_proto_owned(self) -> Proto
Self::into_proto
that types can
optionally implement, otherwise, the default implementation
delegates to Self::into_proto
.impl<T> Eq for LazyProto<T>
Auto Trait Implementations§
impl<T> !Freeze for LazyProto<T>
impl<T> RefUnwindSafe for LazyProto<T>
impl<T> Send for LazyProto<T>
impl<T> Sync for LazyProto<T>
impl<T> Unpin for LazyProto<T>
impl<T> UnwindSafe for LazyProto<T>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> PreferredContainer for T
impl<T> PreferredContainer for T
source§impl<T> ProgressEventTimestamp for T
impl<T> ProgressEventTimestamp for T
source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto
.source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto
.source§impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
source§fn plus_equals(&mut self, rhs: &&'a S)
fn plus_equals(&mut self, rhs: &&'a S)
std::ops::AddAssign
, for types that do not implement AddAssign
.