Struct WasmCodec

Source
pub struct WasmCodec { /* private fields */ }
Expand description

Codec instantiated inside a WebAssembly component.

WasmCodec does not implement the Codec, DynCodec, Clone, or Drop traits itself so that it can expose un-opinionated bindings. However, it provides methods that can be used to implement these traits on a wrapper.

Implementations§

Source§

impl WasmCodec

Methods for implementing the Codec trait

Source

pub fn encode( &self, ctx: impl AsContextMut, data: AnyCowArray<'_>, ) -> Result<Result<AnyArray, CodecError>, RuntimeError>

Encodes the data and returns the result.

The ctx must refer to the same store in which the component was instantiated.

§Errors

Errors with a

Source

pub fn decode( &self, ctx: impl AsContextMut, encoded: AnyCowArray<'_>, ) -> Result<Result<AnyArray, CodecError>, RuntimeError>

Decodes the encoded data and returns the result.

The ctx must refer to the same store in which the component was instantiated.

§Errors

Errors with a

Source

pub fn decode_into( &self, ctx: impl AsContextMut, encoded: AnyArrayView<'_>, decoded: AnyArrayViewMut<'_>, ) -> Result<Result<(), CodecError>, RuntimeError>

Decodes the encoded data and writes the result into the provided decoded output.

The output must have the correct type and shape.

The ctx must refer to the same store in which the component was instantiated.

§Errors

Errors with a

Source§

impl WasmCodec

Methods for implementing the DynCodec trait

Source

pub fn ty(&self) -> WasmCodecComponent

Returns the component object for this codec.

Source

pub fn get_config<S: Serializer>( &self, ctx: impl AsContextMut, serializer: S, ) -> Result<S::Ok, S::Error>

Serializes the configuration parameters for this codec.

The ctx must refer to the same store in which the component was instantiated.

§Errors

Errors if serializing the codec configuration or interacting with the component fails.

Source§

impl WasmCodec

Methods for implementing the Clone trait

Source

pub fn try_clone(&self, ctx: impl AsContextMut) -> Result<Self, Error>

Try cloning the codec by recreating it from its configuration.

The ctx must refer to the same store in which the component was instantiated.

§Errors

Errors if serializing the codec configuration, constructing the new codec, or interacting with the component fails.

Source

pub fn try_clone_into( &self, ctx_from: impl AsContextMut, ctx_into: impl AsContextMut, ) -> Result<Self, Error>

Try cloning the codec into a different context by recreating it from its configuration.

The ctx_from must refer to the same store in which the component was instantiated.

§Errors

Errors if serializing the codec configuration, constructing the new codec, or interacting with the component fails.

Source§

impl WasmCodec

Methods for implementing the Drop trait

Source

pub fn try_drop(&self, ctx: impl AsContextMut) -> Result<(), RuntimeError>

Try dropping the codec.

The ctx must refer to the same store in which the component was instantiated.

§Errors

Errors if the codec’s resource is borrowed or has already been dropped.

Auto Trait Implementations§

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

Source§

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

Source§

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.