Struct codee::binary::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 into a byte stream.
To use it with local storage in the example below we wrap it with [Base64] to represent the bytes as a string.
§Example
ⓘ
// Primitive types:
let (get, set, remove) = use_local_storage::<i32, Base64<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, Base64<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§
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> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
source§impl<T, D> HybridDecoder<T, [u8]> for D
impl<T, D> HybridDecoder<T, [u8]> for D
type Error = <D as Decoder<T>>::Error
fn is_binary_decoder() -> bool
fn decode_bin( val: &[u8], ) -> Result<T, HybridCoderError<<D as HybridDecoder<T, [u8]>>::Error>>
fn decode_str(_val: &str) -> Result<T, HybridCoderError<Self::Error>>
source§impl<T, E> HybridEncoder<T, Vec<u8>> for E
impl<T, E> HybridEncoder<T, Vec<u8>> for E
type Error = <E as Encoder<T>>::Error
fn is_binary_encoder() -> bool
fn encode_bin( val: &T, ) -> Result<Vec<u8>, HybridCoderError<<E as HybridEncoder<T, Vec<u8>>>::Error>>
fn encode_str(_val: &T) -> Result<String, HybridCoderError<Self::Error>>
source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.