Struct PayloadWriter
pub struct PayloadWriter { /* private fields */ }Expand description
A payload body being written, bounded in bytes. The first failure is kept and every later write is skipped, so a codec need not check each one.
Implementations§
§impl PayloadWriter
impl PayloadWriter
pub fn new(limit: usize) -> PayloadWriter
pub fn new(limit: usize) -> PayloadWriter
A writer that accepts at most limit bytes.
pub fn finish(self) -> Result<Vec<u8>, PayloadEncodeError>
pub fn finish(self) -> Result<Vec<u8>, PayloadEncodeError>
The encoded body, or the first failure.
pub fn fail(&mut self, error: PayloadEncodeError)
pub fn fail(&mut self, error: PayloadEncodeError)
Records a failure of the value’s own codec; the first one is kept.
pub fn raw(&mut self, bytes: &[u8])
pub fn raw(&mut self, bytes: &[u8])
Appends bytes as they are, with no length before them. The limit is checked before the buffer grows.
pub fn finite_f32(&mut self, value: f32)
pub fn finite_f32(&mut self, value: f32)
A 32-bit float that must be finite.
pub fn finite_f64(&mut self, value: f64)
pub fn finite_f64(&mut self, value: f64)
A 64-bit float that must be finite.
pub fn bytes(&mut self, bytes: &[u8], limit: usize)
pub fn bytes(&mut self, bytes: &[u8], limit: usize)
A byte array of at most limit bytes: its VarInt length, then the bytes.
pub fn str_within(&mut self, text: &str, limit: usize)
pub fn str_within(&mut self, text: &str, limit: usize)
A string of at most limit UTF-8 bytes: its VarInt byte length, then
the bytes.
pub fn string(&mut self, text: &str)
pub fn string(&mut self, text: &str)
A string of at most PAYLOAD_MAX_STRING_BYTES UTF-8 bytes.
pub fn nested(&mut self, write: impl FnOnce(&mut PayloadWriter))
pub fn nested(&mut self, write: impl FnOnce(&mut PayloadWriter))
Writes one level down, refusing past PAYLOAD_MAX_DEPTH.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PayloadWriter
impl RefUnwindSafe for PayloadWriter
impl Send for PayloadWriter
impl Sync for PayloadWriter
impl Unpin for PayloadWriter
impl UnsafeUnpin for PayloadWriter
impl UnwindSafe for PayloadWriter
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