logos.std.io.bytes
Module std · package logos-std
Types
structBytes
struct Bytes
Refcounted immutable byte slice; cheap to clone (refcount bump) and to slice (zero-copy). The buffer’s refcount is atomic, so handles may cross fibers/threads.
Implements: Iterator
Fields
inner: *mut BytesInner
len: i64
offset: i64
Methods
fn as_ptr(self: *mut Bytes) -> *const u8
Returns a pointer to the first byte of the view; null when the handle owns no buffer.
fn clone_bytes(self: *mut Bytes) -> Bytes
Returns a new handle to the same buffer and range (refcount bump; no copy).
fn drop_bytes(self: *mut Bytes) -> void
Releases this handle and resets it to empty; frees the buffer when the last handle drops. Idempotent: calling again on the emptied handle is a no-op.
fn get(self: *mut Bytes, i: i64) -> u8
Returns the byte at index i. No bounds check: i outside [0, len) or an
empty handle is undefined behavior.
fn is_empty(self: *mut Bytes) -> bool
Returns true if this view has zero length.
fn slice(self: *mut Bytes, start: i64, end: i64) -> Bytes
Returns a zero-copy sub-view over [start, end); indices are clamped to the slice.
structBytesMut
struct BytesMut
Owned mutable byte buffer for building Bytes; grows on demand, freeze yields the
immutable view.
Fields
inner: *mut BytesInner
len: i64
Methods
fn as_mut_ptr(self: *mut BytesMut) -> *mut u8
Returns a write pointer to the buffer start; null when nothing is allocated.
Invalidated by any growing call (reserve, push_byte, extend_*).
fn as_ptr(self: *mut BytesMut) -> *const u8
Returns a read pointer to the buffer start; null when nothing is allocated.
fn capacity(self: *mut BytesMut) -> i64
Returns the current allocated capacity in bytes.
fn drop_mut(self: *mut BytesMut) -> void
Releases the underlying buffer and resets this handle to empty; frees the buffer when the last handle drops.
fn extend_from_slice(self: *mut BytesMut, src: *const u8, n: i64) -> void
Appends n bytes copied from src, growing the buffer if needed; n <= 0 is a no-op.
fn extend_from_str(self: *mut BytesMut, s: &[u8]) -> void
Appends the contents of s.
fn extend_from_string(self: *mut BytesMut, s: &String) -> void
Appends the contents of s.
fn freeze(self: *mut BytesMut) -> Bytes
Hands out an immutable Bytes view covering the populated region.
Consumes the BytesMut (caller must not reuse it; it is reset to empty).
fn push_byte(self: *mut BytesMut, b: u8) -> void
Appends a single byte, growing the buffer if needed.
fn reserve(self: *mut BytesMut, additional: i64) -> void
Ensures capacity for at least additional more bytes beyond the current length.
Grows geometrically (doubling, minimum 8), reallocating the buffer in place.
Functions
fnbytes_empty
fn bytes_empty() -> Bytes
Returns an empty Bytes that owns no buffer.
fnbytes_from_slice
fn bytes_from_slice(src: *const u8, len: i64) -> Bytes
Creates a Bytes by copying len bytes from src into a fresh buffer.
len <= 0 yields the empty Bytes without reading src.
fnbytes_from_str
fn bytes_from_str(s: &[u8]) -> Bytes
Creates a Bytes by copying the contents of s.
fnbytes_from_string
fn bytes_from_string(s: &String) -> Bytes
Creates a Bytes by copying the contents of s.
fnbytes_mut_new
fn bytes_mut_new() -> BytesMut
Creates an empty BytesMut with no preallocated storage.
fnbytes_mut_with_capacity
fn bytes_mut_with_capacity(cap: i64) -> BytesMut
Creates an empty BytesMut with at least cap bytes of capacity preallocated.