Skip to main content

EmptyChunk

Trait EmptyChunk 

Source
pub trait EmptyChunk {
    // Required method
    fn empty() -> Self
       where Self: Sized;
}
Expand description

A trait for chunk-like buffer types (such as Chunk and ChunkMut) that can be instantiated directly as empty.

Required Methods§

Source

fn empty() -> Self
where Self: Sized,

Creates an empty buffer instance.

The returned value must represent an empty view of the underlying data. For types implementing Chunk, this implies remaining() == 0 and buffer().is_empty(). For mutable chunk-like types (such as ChunkMut), this implies there are no readable or writable bytes available according to that type’s API.

This is a convenience method for creating an empty buffer of the implementing type.

§Examples
use bufkit::{Chunk, EmptyChunk};

let empty_buf = <&[u8]>::empty();
assert_eq!(empty_buf.remaining(), 0);
assert!(empty_buf.buffer().is_empty());

Implementations on Foreign Types§

Source§

impl EmptyChunk for &[u8]

Source§

fn empty() -> Self
where Self: Sized,

Source§

impl EmptyChunk for &mut [u8]

Source§

fn empty() -> Self
where Self: Sized,

use bufkit::{EmptyChunk, ChunkMut};

let mut slice = <&mut [u8]>::empty();
assert_eq!(slice.remaining_mut(), 0);
assert!(!slice.has_remaining_mut());
Source§

impl EmptyChunk for Bytes

Available on crate feature bytes_1 and (crate features std or alloc) only.
Source§

fn empty() -> Self
where Self: Sized,

use bufkit::{EmptyChunk, Chunk};
use bytes_1::Bytes;

let empty = Bytes::empty();
assert_eq!(empty.remaining(), 0);
assert!(!empty.has_remaining());
Source§

impl<T: EmptyChunk> EmptyChunk for Box<T>

Available on crate features std or alloc only.
Source§

fn empty() -> Self
where Self: Sized,

use bufkit::{EmptyChunk, ChunkMut};

let mut slice = <Box<&mut [u8]>>::empty();
assert_eq!(slice.remaining_mut(), 0);
assert!(!slice.has_remaining_mut());

Implementors§