Skip to main content

DiscardSeq

Struct DiscardSeq 

Source
pub struct DiscardSeq<T, Len>(/* private fields */);
Expand description

Discards a length-prefixed sequence: reads the length (encoded per Len) and steps over every element with the element schema T, advancing the reader exactly as decoding the sequence would, yet never allocates a backing buffer and always yields an empty Vec.

Every wincode sequence — Vec, String, slices, sets, and maps — shares the same length prefix + elements wire layout, so this discards any of them; T only names one element’s wire form:

  • a Vec<u32>: DiscardSeq<u32, Len>;
  • a String: DiscardSeq<u8, Len> (identical bytes to a Vec<u8>);
  • a map such as HashMap<K, V> / BTreeMap<K, V>: DiscardSeq<(K, V), Len>, since each entry is encoded as a (K, V) pair;
  • nested sequences, with no allocation at any level: DiscardSeq<DiscardSeq<u8, L2>, L1> for a Vec<Vec<u8>>.

The produced value is always an empty Vec<T::Dst>, and that type is incidental. Deprecating a field is then just repointing it at DiscardSeq and changing its type to the matching Vec<…>: the field is dead, so its concrete collection type no longer matters — only that the bytes are consumed and the stream stays aligned.

The length prefix is still validated against the configured preallocation limit, so a hostile length errors out identically to a real read.

Like Discard, the sequence held in the instance is ignored on write and an empty sequence is emitted, matching what read reconstructs. Use the configuration’s default length encoding, e.g. BincodeLen, to match how the field was originally encoded.

#[derive(SchemaWrite, SchemaRead, Debug, PartialEq)]
struct Full {
    data: Vec<u32>,
    tag: u8,
}

#[derive(SchemaWrite, SchemaRead, Debug, PartialEq)]
struct Partial {
    #[wincode(with = "DiscardSeq<u32, BincodeLen>")]
    data: Vec<u32>,
    tag: u8,
}

// On read, `data` is stepped over and reset to an empty `Vec`.
let bytes = wincode::serialize(&Full { data: vec![1, 2, 3], tag: 42 }).unwrap();
assert_eq!(
    wincode::deserialize::<Partial>(&bytes).unwrap(),
    Partial { data: Vec::new(), tag: 42 },
);

// On write, `data` is discarded and an empty sequence is serialized, so the
// output matches a `Full` with empty `data`.
let out = wincode::serialize(&Partial { data: vec![1, 2, 3], tag: 42 }).unwrap();
assert_eq!(out, wincode::serialize(&Full { data: vec![], tag: 42 }).unwrap());

Trait Implementations§

Source§

impl<'de, C, T, Len> SchemaRead<'de, C> for DiscardSeq<T, Len>
where C: ConfigCore, Len: SeqLen<C>, T: SchemaRead<'de, C>,

Available on crate feature alloc only.
Source§

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

Source§

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

Read into dst from reader. Read more
Source§

const TYPE_META: TypeMeta = TypeMeta::Dynamic

Metadata about the type’s serialization. Read more
Source§

fn get(reader: impl Reader<'de>) -> ReadResult<Self::Dst>

Read Self::Dst from reader into a new Self::Dst.
Source§

impl<C, T, Len> SchemaWrite<C> for DiscardSeq<T, Len>
where C: ConfigCore, Len: SeqLen<C>, T: SchemaWrite<C>, T::Src: Sized,

Available on crate feature alloc only.
Source§

type Src = Vec<<T as SchemaWrite<C>>::Src>

Source§

fn size_of(_src: &Self::Src) -> WriteResult<usize>

Get the serialized size of Self::Src. Read more
Source§

fn write(writer: impl Writer, _src: &Self::Src) -> WriteResult<()>

Write Self::Src to writer.
Source§

const TYPE_META: TypeMeta = TypeMeta::Dynamic

Metadata about the type’s serialization. Read more

Auto Trait Implementations§

§

impl<T, Len> Freeze for DiscardSeq<T, Len>

§

impl<T, Len> RefUnwindSafe for DiscardSeq<T, Len>

§

impl<T, Len> Send for DiscardSeq<T, Len>
where PhantomData<T>: Send, PhantomData<Len>: Send,

§

impl<T, Len> Sync for DiscardSeq<T, Len>
where PhantomData<T>: Sync, PhantomData<Len>: Sync,

§

impl<T, Len> Unpin for DiscardSeq<T, Len>

§

impl<T, Len> UnsafeUnpin for DiscardSeq<T, Len>

§

impl<T, Len> UnwindSafe for DiscardSeq<T, Len>

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<'de, T, C> Deserialize<'de, C> for T
where C: Config, T: SchemaRead<'de, C>,

Source§

fn deserialize(src: &'de [u8], config: C) -> ReadResult<Self::Dst>

Deserialize the input bytes into a new Self::Dst.
Source§

fn deserialize_into( src: &'de [u8], dst: &mut MaybeUninit<Self::Dst>, config: C, ) -> ReadResult<()>

Deserialize the input bytes into dst.
Source§

impl<'de, T> Deserialize<'de> for T
where T: SchemaRead<'de, Configuration>,

Source§

fn deserialize(src: &'de [u8]) -> ReadResult<Self::Dst>

Deserialize the input src bytes into a new Self::Dst.
Source§

fn deserialize_into( src: &'de [u8], dst: &mut MaybeUninit<Self::Dst>, ) -> ReadResult<()>

Deserialize the input src bytes into dst.
Source§

impl<T> DeserializeOwned for T

Source§

fn deserialize_from<'de>( src: impl Reader<'de>, ) -> ReadResult<<Self as SchemaRead<'de, DefaultConfig>>::Dst>

Deserialize from the given Reader into a new Self::Dst.
Source§

fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<<Self as SchemaRead<'de, DefaultConfig>>::Dst>, ) -> ReadResult<()>

Deserialize from the given Reader into dst.
Source§

impl<T, C> DeserializeOwned<C> for T
where C: Config, T: SchemaReadOwned<C>,

Source§

fn deserialize_from<'de>( src: impl Reader<'de>, ) -> ReadResult<<Self as SchemaRead<'de, C>>::Dst>

Deserialize from the given Reader into a new Self::Dst.
Source§

fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<<Self as SchemaRead<'de, C>>::Dst>, ) -> ReadResult<()>

Deserialize from the given Reader into dst.
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, C> SchemaReadOwned<C> for T
where C: ConfigCore, T: for<'de> SchemaRead<'de, C>,

Source§

impl<T> Serialize for T

Source§

fn serialize(src: &Self::Src) -> WriteResult<Vec<u8>>

Serialize a serializable type into a Vec of bytes.
Source§

fn serialize_into(dst: impl Writer, src: &Self::Src) -> WriteResult<()>

Serialize a serializable type into the given byte buffer. Read more
Source§

fn serialized_size(src: &Self::Src) -> WriteResult<u64>

Get the size in bytes of the type when serialized.
Source§

impl<T, C> Serialize<C> for T
where C: Config, T: SchemaWrite<C> + ?Sized,

Source§

fn serialize(src: &Self::Src, config: C) -> WriteResult<Vec<u8>>

Serialize a serializable type into a Vec of bytes.
Source§

fn serialize_into( dst: impl Writer, src: &Self::Src, config: C, ) -> WriteResult<()>

Serialize a serializable type into the given Writer. Read more
Source§

fn serialized_size(src: &Self::Src, config: C) -> WriteResult<u64>

Get the size in bytes of the type when serialized.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.