pub struct CustomSerDes<T, S, D>where
T: Send + Sync,
S: Fn(&T, &SerDesContext) -> Result<String, SerDesError> + Send + Sync,
D: Fn(&str, &SerDesContext) -> Result<T, SerDesError> + Send + Sync,{ /* private fields */ }Expand description
A custom serializer/deserializer that delegates to user-provided closures.
This struct allows users to provide custom serialization behavior without
implementing the sealed SerDes trait directly.
§Type Parameters
T- The type to serialize/deserializeS- The serialization closure typeD- The deserialization closure type
§Example
use durable_execution_sdk::serdes::{custom_serdes, SerDes, SerDesContext, SerDesError};
// Create a custom serializer for strings that adds a prefix
let serdes = custom_serdes::<String, _, _>(
|value, _ctx| Ok(format!("PREFIX:{}", value)),
|data, _ctx| {
data.strip_prefix("PREFIX:")
.map(|s| s.to_string())
.ok_or_else(|| SerDesError::deserialization("Missing PREFIX"))
},
);Trait Implementations§
Source§impl<T, S, D> Debug for CustomSerDes<T, S, D>where
T: Send + Sync,
S: Fn(&T, &SerDesContext) -> Result<String, SerDesError> + Send + Sync,
D: Fn(&str, &SerDesContext) -> Result<T, SerDesError> + Send + Sync,
impl<T, S, D> Debug for CustomSerDes<T, S, D>where
T: Send + Sync,
S: Fn(&T, &SerDesContext) -> Result<String, SerDesError> + Send + Sync,
D: Fn(&str, &SerDesContext) -> Result<T, SerDesError> + Send + Sync,
Source§impl<T, S, D> SerDes<T> for CustomSerDes<T, S, D>where
T: Send + Sync,
S: Fn(&T, &SerDesContext) -> Result<String, SerDesError> + Send + Sync,
D: Fn(&str, &SerDesContext) -> Result<T, SerDesError> + Send + Sync,
impl<T, S, D> SerDes<T> for CustomSerDes<T, S, D>where
T: Send + Sync,
S: Fn(&T, &SerDesContext) -> Result<String, SerDesError> + Send + Sync,
D: Fn(&str, &SerDesContext) -> Result<T, SerDesError> + Send + Sync,
Source§fn serialize(
&self,
value: &T,
context: &SerDesContext,
) -> Result<String, SerDesError>
fn serialize( &self, value: &T, context: &SerDesContext, ) -> Result<String, SerDesError>
Serializes a value to a string representation. Read more
Source§fn deserialize(
&self,
data: &str,
context: &SerDesContext,
) -> Result<T, SerDesError>
fn deserialize( &self, data: &str, context: &SerDesContext, ) -> Result<T, SerDesError>
Deserializes a string representation back to a value. Read more
Auto Trait Implementations§
impl<T, S, D> Freeze for CustomSerDes<T, S, D>
impl<T, S, D> RefUnwindSafe for CustomSerDes<T, S, D>
impl<T, S, D> Send for CustomSerDes<T, S, D>
impl<T, S, D> Sync for CustomSerDes<T, S, D>
impl<T, S, D> Unpin for CustomSerDes<T, S, D>
impl<T, S, D> UnsafeUnpin for CustomSerDes<T, S, D>where
S: UnsafeUnpin,
D: UnsafeUnpin,
impl<T, S, D> UnwindSafe for CustomSerDes<T, S, D>
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 moreCreates a shared type from an unshared type.