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,

source

pub fn into_inner(self) -> T

Trait Implementations§

source§

impl<T> AsRef<T> for Serializable<T>
where T: SerializerT,

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> BorshDeserialize for Serializable<T>
where T: SerializerT,

source§

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>

source§

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>

Deserialize this instance from a slice of bytes.
source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

source§

impl<T> BorshSerialize for Serializable<T>
where T: SerializerT,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

source§

impl<T> Debug for Serializable<T>
where T: SerializerT + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Deref for Serializable<T>
where T: SerializerT,

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> From<T> for Serializable<T>
where T: SerializerT,

source§

fn from(t: T) -> Self

Converts to this type from the input type.
source§

impl<T> Serialize for Serializable<T>

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,