Struct leptos_use::utils::ProstCodec
source · pub struct ProstCodec;
Expand description
A codec for storing ProtoBuf messages that relies on prost
to parse.
Protocol buffers is a serialisation format useful for long-term storage. It provides semantics for versioning that are not present in JSON or other formats. prost
is a Rust implementation of Protocol Buffers.
This codec uses prost
to encode the message and then base64
to represent the bytes as a string.
§Example
// Primitive types:
let (get, set, remove) = use_local_storage::<i32, ProstCodec>("my-key");
// Structs:
#[derive(Clone, PartialEq, prost::Message)]
pub struct MyState {
#[prost(string, tag = "1")]
pub hello: String,
}
let (get, set, remove) = use_local_storage::<MyState, ProstCodec>("my-struct-key");
Note: we’ve defined and used the prost
attribute here for brevity. Alternate usage would be to describe the message in a .proto file and use prost_build
to auto-generate the Rust code.
Trait Implementations§
source§impl Clone for ProstCodec
impl Clone for ProstCodec
source§fn clone(&self) -> ProstCodec
fn clone(&self) -> ProstCodec
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Default for ProstCodec
impl Default for ProstCodec
source§fn default() -> ProstCodec
fn default() -> ProstCodec
Returns the “default value” for a type. Read more
source§impl PartialEq for ProstCodec
impl PartialEq for ProstCodec
source§fn eq(&self, other: &ProstCodec) -> bool
fn eq(&self, other: &ProstCodec) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl<T: Default + Message> StringCodec<T> for ProstCodec
impl<T: Default + Message> StringCodec<T> for ProstCodec
§type Error = ProstCodecError
type Error = ProstCodecError
The error type returned when encoding or decoding fails.
impl Copy for ProstCodec
impl StructuralPartialEq for ProstCodec
Auto Trait Implementations§
impl Freeze for ProstCodec
impl RefUnwindSafe for ProstCodec
impl Send for ProstCodec
impl Sync for ProstCodec
impl Unpin for ProstCodec
impl UnwindSafe for ProstCodec
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
Mutably borrows from an owned value. Read more
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>
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 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>
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