Struct workflow_serializer::serializer::Serializable
source · #[repr(transparent)]pub struct Serializable<T>(pub T)
where
T: SerializerT;
Expand description
Serializable<T>
is a stop-gap between Borsh serialization
and the actual type T
that needs to be serialized.
T
must implement Serializer
as opposed to Borsh traits,
while Serializable<T>
implements Borsh traits.
This allows functions requiring Borsh serialization to accept
T that does not implement Borsh traits by wrapping it in
Serializable<T>
.
Example:
ⓘ
struct MyStruct {
field: u32,
}
impl Serializer for MyStruct {
fn serialize<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
store!(u32, &1, writer)?;
store!(u32, &self.field, writer)?;
Ok(())
}
fn deserialize(buf: &mut &[u8]) -> std::io::Result<Self> {
let _version = load!(u32, buf)?;
let field = load!(u32, buf)?;
Ok(Self { field })
}
}
fn send<T>(serializable: T) where T : BorshSerialize { ... }
fn sender() {
let my_struct = MyStruct { field: 42 };
send(Serializable(my_struct));
}
Tuple Fields§
§0: T
Implementations§
source§impl<T> Serializable<T>where
T: SerializerT,
impl<T> Serializable<T>where
T: SerializerT,
pub fn into_inner(self) -> T
Trait Implementations§
source§impl<T> AsRef<T> for Serializable<T>where
T: SerializerT,
impl<T> AsRef<T> for Serializable<T>where
T: SerializerT,
source§impl<T> BorshDeserialize for Serializable<T>where
T: SerializerT,
impl<T> BorshDeserialize for Serializable<T>where
T: SerializerT,
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>
source§fn deserialize(buf: &mut &[u8]) -> Result<Self>
fn deserialize(buf: &mut &[u8]) -> Result<Self>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
source§impl<T> BorshSerialize for Serializable<T>where
T: SerializerT,
impl<T> BorshSerialize for Serializable<T>where
T: SerializerT,
source§impl<T> Debug for Serializable<T>where
T: SerializerT + Debug,
impl<T> Debug for Serializable<T>where
T: SerializerT + Debug,
source§impl<T> Deref for Serializable<T>where
T: SerializerT,
impl<T> Deref for Serializable<T>where
T: SerializerT,
source§impl<'de, T> Deserialize<'de> for Serializable<T>where
T: SerializerT + Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Serializable<T>where
T: SerializerT + Deserialize<'de>,
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>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<T> From<T> for Serializable<T>where
T: SerializerT,
impl<T> From<T> for Serializable<T>where
T: SerializerT,
source§impl<T> Serialize for Serializable<T>where
T: SerializerT + Serialize,
impl<T> Serialize for Serializable<T>where
T: SerializerT + Serialize,
Auto Trait Implementations§
impl<T> Freeze for Serializable<T>where
T: Freeze,
impl<T> RefUnwindSafe for Serializable<T>where
T: RefUnwindSafe,
impl<T> Send for Serializable<T>
impl<T> Sync for Serializable<T>
impl<T> Unpin for Serializable<T>where
T: Unpin,
impl<T> UnwindSafe for Serializable<T>where
T: UnwindSafe,
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