Skip to main content

SchemaReadContext

Trait SchemaReadContext 

Source
pub unsafe trait SchemaReadContext<'de, C: ConfigCore, Ctx> {
    type Dst;

    const TYPE_META: TypeMeta = TypeMeta::Dynamic;

    // Required method
    fn read_with_context(
        ctx: Ctx,
        reader: impl Reader<'de>,
        dst: &mut MaybeUninit<Self::Dst>,
    ) -> ReadResult<()>;

    // Provided method
    fn get_with_context(
        ctx: Ctx,
        reader: impl Reader<'de>,
    ) -> ReadResult<Self::Dst> { ... }
}
Expand description

Types that can be read (deserialized) from a Reader with an additional context parameter.

§Safety

Implementors must adhere to the Safety section of the associated constant TYPE_META (or leave it as the default) and the method read.

Provided Associated Constants§

Source

const TYPE_META: TypeMeta = TypeMeta::Dynamic

Metadata about the type’s serialization.

§Safety

It is always safe to leave this as the default TypeMeta::Dynamic. If you set it to TypeMeta::Static { size, zero_copy }, you have to ensure the following two points:

  • size must always correspond to the number of bytes read by read.
  • If zero_copy is true, Dst’s in-memory representation must correspond exactly to the serialized form, and all byte sequences must be valid in-memory representations of Dst.

Required Associated Types§

Required Methods§

Source

fn read_with_context( ctx: Ctx, reader: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> ReadResult<()>

Read into dst from reader with context.

You must initialize dst if and only if you return Ok(()). In the Err(…) case, initializing dst can lead to memory leaks.

It is permissible to not initialize dst if dst is an inhabited zero-sized type.

Provided Methods§

Source

fn get_with_context(ctx: Ctx, reader: impl Reader<'de>) -> ReadResult<Self::Dst>

Read Self::Dst from reader into a new Self::Dst with context.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'de, C: Config> SchemaReadContext<'de, C, Len> for String

Available on crate feature alloc only.
Source§

type Dst = String

Source§

fn read_with_context( ctx: Len, reader: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> ReadResult<()>

Source§

impl<'de, C: ConfigCore> SchemaReadContext<'de, C, Len> for &'de str

Source§

type Dst = &'de str

Source§

fn read_with_context( context::Len: Len, reader: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> ReadResult<()>

Source§

impl<'de, T, C: ConfigCore> SchemaReadContext<'de, C, Len> for &'de [T]
where T: SchemaRead<'de, C> + ZeroCopy<C>,

Source§

const TYPE_META: TypeMeta

Source§

type Dst = &'de [<T as SchemaRead<'de, C>>::Dst]

Source§

fn read_with_context( context::Len: Len, reader: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> ReadResult<()>

Source§

impl<'de, T, C: ConfigCore> SchemaReadContext<'de, C, Len> for Cow<'de, [T]>
where [T]: ToOwned, &'de [T]: SchemaReadContext<'de, C, Len, Dst = &'de [T]>, <[T] as ToOwned>::Owned: SchemaReadContext<'de, C, Len, Dst = <[T] as ToOwned>::Owned>,

Available on crate feature alloc only.
Source§

type Dst = Cow<'de, [T]>

Source§

fn read_with_context( ctx: Len, reader: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> ReadResult<()>

Source§

impl<'de, T, C: ConfigCore> SchemaReadContext<'de, C, Len> for Vec<T>
where T: SchemaRead<'de, C>,

Available on crate feature alloc only.
Source§

type Dst = Vec<<T as SchemaRead<'de, C>>::Dst>

Source§

fn read_with_context( ctx: Len, reader: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> ReadResult<()>

Implementors§

Source§

impl<'de, const N: usize, C: ConfigCore> SchemaReadContext<'de, C, [u8; N]> for ShortU16

Available on crate feature solana-short-vec only.