pub struct SliceSink<'a> { /* private fields */ }Expand description
A cursor over a caller buffer.
No allocation; reports remaining; a put that does
not fit writes nothing. Debug prints the lengths only, never the bytes.
§Examples
use parse_net::{Sink, SliceSink};
let mut buf = [0u8; 8];
let mut out = SliceSink::new(&mut buf);
out.put(b"gzip")?;
assert_eq!(out.written(), b"gzip");
assert_eq!(out.remaining(), Some(4));
out.clear();
assert!(out.is_empty());Implementations§
Source§impl<'a> SliceSink<'a>
impl<'a> SliceSink<'a>
Sourcepub fn new(buf: &'a mut [u8]) -> Self
pub fn new(buf: &'a mut [u8]) -> Self
A sink that writes into buf, starting at its first byte.
§Examples
use parse_net::{Sink, SliceSink};
let mut buf = [0u8; 4];
let out = SliceSink::new(&mut buf);
assert_eq!((out.len(), out.remaining()), (0, Some(4)));Sourcepub fn written(&self) -> &[u8] ⓘ
pub fn written(&self) -> &[u8] ⓘ
The bytes written so far.
§Examples
use parse_net::{write, SliceSink};
let mut buf = [0u8; 16];
let mut out = SliceSink::new(&mut buf);
write::write_token(b"br", &mut out)?;
assert_eq!(out.written(), b"br");Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The number of bytes written so far.
§Examples
use parse_net::{write, SliceSink};
let mut buf = [0u8; 16];
let mut out = SliceSink::new(&mut buf);
write::write_quoted(b"a b", &mut out)?;
assert_eq!(out.len(), 5);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether nothing has been written.
§Examples
use parse_net::{write, SliceSink};
let mut buf = [0u8; 16];
let mut out = SliceSink::new(&mut buf);
assert!(out.is_empty());
write::write_token(b"gzip", &mut out)?;
assert!(!out.is_empty());Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Forgets what was written; the buffer is reused from its start.
§Examples
use parse_net::{write, SliceSink};
let mut buf = [0u8; 8];
let mut out = SliceSink::new(&mut buf);
write::write_token(b"gzip", &mut out)?;
out.clear();
write::write_token(b"br", &mut out)?;
assert_eq!(out.written(), b"br");Trait Implementations§
Auto Trait Implementations§
impl<'a> !UnwindSafe for SliceSink<'a>
impl<'a> Freeze for SliceSink<'a>
impl<'a> RefUnwindSafe for SliceSink<'a>
impl<'a> Send for SliceSink<'a>
impl<'a> Sync for SliceSink<'a>
impl<'a> Unpin for SliceSink<'a>
impl<'a> UnsafeUnpin for SliceSink<'a>
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