musli_core/de/
decode_slice_builder.rs

1use crate::{Allocator, Context};
2
3/// Trait used to decode a slice into a type.
4pub trait DecodeSliceBuilder<T, A>: Sized
5where
6    A: Allocator,
7{
8    /// Construct a new empty container.
9    fn new<C>(cx: C) -> Result<Self, C::Error>
10    where
11        C: Context<Allocator = A>;
12
13    /// Construct a new container with the given capacity hint.
14    fn with_capacity<C>(cx: C, capacity: usize) -> Result<Self, C::Error>
15    where
16        C: Context<Allocator = A>;
17
18    /// Push a value into the container.
19    fn push<C>(&mut self, cx: C, value: T) -> Result<(), C::Error>
20    where
21        C: Context<Allocator = A>;
22
23    /// Reserve additional space for `capacity` elements in the collection.
24    fn reserve<C>(&mut self, cx: C, capacity: usize) -> Result<(), C::Error>
25    where
26        C: Context<Allocator = A>;
27
28    /// Mark the given length as initialized.
29    ///
30    /// # Safety
31    ///
32    /// The caller must ensure that elements up from `old_len..len` have been
33    /// initialized.
34    unsafe fn set_len(&mut self, len: usize);
35
36    /// Get a mutable pointer to the first element in the collection.
37    fn as_mut_ptr(&mut self) -> *mut T;
38}