Skip to main content

SliceSink

Struct SliceSink 

Source
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>

Source

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)));
Source

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");
Source

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);
Source

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());
Source

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§

Source§

impl Debug for SliceSink<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Sink for SliceSink<'_>

Source§

fn put(&mut self, bytes: &[u8]) -> Result<(), Full>

Appends all of bytes, or fails with Full and appends nothing. Read more
Source§

fn remaining(&self) -> Option<usize>

How many more bytes fit, when the sink knows; None otherwise.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.