1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
//! Serializer trait and default implementation.
pub mod impls;
use crate::Error;
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
/// Serialization abstract with type to serialize.
///
/// Serializer implementations must implement this trait.
pub trait TypedSerialized {
/// Type to serialize
type T;
/// Constructor
fn new(serialized: Vec<u8>) -> Self
where
Self: Sized;
/// Ref to serialized.
fn as_slice(&self) -> &[u8];
/// Into serialized.
fn into_vec(self) -> Vec<u8>;
/// # Failures
///
/// - [SerializationError](serde_encrypt_core::error::ErrorKind::SerializationError) when failed to serialize message.
fn serialize(v: &Self::T) -> Result<Self, Error>
where
Self: Sized,
Self::T: Serialize;
/// # Failures
///
/// - [DeserializationError](serde_encrypt_core::error::ErrorKind::DeserializationError) when failed to deserialize decrypted message.
fn deserialize<'de>(&'de self) -> Result<Self::T, Error>
where
Self::T: Deserialize<'de>;
}