#[repr(transparent)]pub struct Array<T>(pub Vec<T>);Expand description
A sequence of protocol values whose element count is supplied by context.
Array<T> has no wire length prefix. The enclosing packet must supply the
number of elements through Context::for_array_length or
Context::with_array_length. Exactly that many values are encoded or
decoded. A zero length therefore produces and consumes zero bytes.
The total byte size is not necessarily length * fixed_size: if T has a
variable-size encoding, each element may occupy a different number of
bytes.
§Examples
use mcproto_types::{ContextualCodec, TypeCodec, basic::UnsignedByte};
use mcproto_types::contextual::{Array, Context};
let values = Array(vec![UnsignedByte(1), UnsignedByte(2)]);
let mut encoded = Vec::new();
values.encode_with_context(&mut encoded, &Context::for_array_length(2))?;
assert_eq!(encoded, [1, 2]);
let mut input = encoded.as_slice();
assert_eq!(
Array::<UnsignedByte>::decode_with_context(
&mut input,
&Context::for_array_length(2),
)?,
values,
);Tuple Fields§
§0: Vec<T>The array elements.
Implementations§
Trait Implementations§
Source§impl<T> ContextualCodec for Array<T>where
T: ContextualCodec,
impl<T> ContextualCodec for Array<T>where
T: ContextualCodec,
Source§fn encode_with_context(
&self,
writer: &mut impl Write,
context: &Context,
) -> Result<(), CodecError>
fn encode_with_context( &self, writer: &mut impl Write, context: &Context, ) -> Result<(), CodecError>
Encodes this value using context supplied by its enclosing structure.
Source§fn decode_with_context(
reader: &mut impl Read,
context: &Context,
) -> Result<Self, CodecError>
fn decode_with_context( reader: &mut impl Read, context: &Context, ) -> Result<Self, CodecError>
Decodes this value using context supplied by its enclosing structure.
impl<T: Eq> Eq for Array<T>
impl<T: PartialEq> StructuralPartialEq for Array<T>
Auto Trait Implementations§
impl<T> Freeze for Array<T>
impl<T> RefUnwindSafe for Array<T>where
T: RefUnwindSafe,
impl<T> Send for Array<T>where
T: Send,
impl<T> Sync for Array<T>where
T: Sync,
impl<T> Unpin for Array<T>where
T: Unpin,
impl<T> UnsafeUnpin for Array<T>
impl<T> UnwindSafe for Array<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