pub struct Encoder<W> { /* private fields */ }
Expand description
A non-allocating CBOR encoder writing encoded bytes to the given Write
sink.
Implementations
sourceimpl<W: Write> Encoder<W>
impl<W: Write> Encoder<W>
sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Get back the Write
impl.
sourcepub fn encode<T: Encode>(&mut self, x: T) -> Result<&mut Self, Error<W::Error>>
pub fn encode<T: Encode>(&mut self, x: T) -> Result<&mut Self, Error<W::Error>>
Encode any type that implements Encode
.
sourcepub fn undefined(&mut self) -> Result<&mut Self, Error<W::Error>>
pub fn undefined(&mut self) -> Result<&mut Self, Error<W::Error>>
Encode a CBOR undefined
value.
sourcepub fn simple(&mut self, x: u8) -> Result<&mut Self, Error<W::Error>>
pub fn simple(&mut self, x: u8) -> Result<&mut Self, Error<W::Error>>
Encode a CBOR simple value.
sourcepub fn f16(&mut self, x: f32) -> Result<&mut Self, Error<W::Error>>
pub fn f16(&mut self, x: f32) -> Result<&mut Self, Error<W::Error>>
Encode an f32
value as a half float (f16)
.
Requires feature "half"
.
NB: The conversion from f32
to f16
is potentially lossy.
Generally values are truncated and rounded to the nearest 16-bit
value, except:
- 32-bit values which do not fit into 16 bit become ±∞.
- 32-bit subnormal values become ±0.
- Exponents smaller than the min. 16-bit exponent become 16-bit subnormals or ±0.
For further details please consult the half crate which is
used internally for f16
support.
sourcepub fn array(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
pub fn array(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
Begin encoding an array with len
elements.
sourcepub fn map(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
pub fn map(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
Begin encoding a map with len
entries.
sourcepub fn begin_array(&mut self) -> Result<&mut Self, Error<W::Error>>
pub fn begin_array(&mut self) -> Result<&mut Self, Error<W::Error>>
Begin encoding an array of unknown size.
Use Encoder::end
to terminate the array.
sourcepub fn begin_bytes(&mut self) -> Result<&mut Self, Error<W::Error>>
pub fn begin_bytes(&mut self) -> Result<&mut Self, Error<W::Error>>
Begin encoding an indefinite number of byte slices.
Use Encoder::end
to terminate.
sourcepub fn begin_map(&mut self) -> Result<&mut Self, Error<W::Error>>
pub fn begin_map(&mut self) -> Result<&mut Self, Error<W::Error>>
Begin encoding a map of unknown size.
Use Encoder::end
to terminate the map.
sourcepub fn begin_str(&mut self) -> Result<&mut Self, Error<W::Error>>
pub fn begin_str(&mut self) -> Result<&mut Self, Error<W::Error>>
Begin encoding an indefinite number of string slices.
Use Encoder::end
to terminate.
Trait Implementations
Auto Trait Implementations
impl<W> RefUnwindSafe for Encoder<W> where
W: RefUnwindSafe,
impl<W> Send for Encoder<W> where
W: Send,
impl<W> Sync for Encoder<W> where
W: Sync,
impl<W> Unpin for Encoder<W> where
W: Unpin,
impl<W> UnwindSafe for Encoder<W> where
W: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more