Module coil-stdlib

bytes

Byte buffers are Vec<byte>. Offsets are byte offsets, and nothing here knows about UTF-8; use text for strings. A string literal can be passed where a Vec<byte> is expected.

Part of coil-stdlib. spool projects get it automatically; with plain coil, pass --root ~/.coil/stdlib/src.

Import what you use (use path::* is not allowed):

use bytes::{Bytes, region_eq};

Types#

NameDescription
BytesA wrapper around a Vec<byte>, for APIs that want a distinct byte-buffer type.

Functions#

NameDescription
region_eqTrue when a[ao..ao+n) equals b[bo..bo+n) (caller guarantees bounds).
to_hexEncodes buf as lowercase hexadecimal, two digits per byte.
from_hexDecodes hexadecimal text (either case) into bytes.
sliceReturns a copy of src[start..end] (end exclusive), with both offsets clamped to the buffer.
concatReturns a new buffer holding a followed by b.
eqReturns true when a and b have the same length and the same bytes.
find_fromReturns the offset of the first needle in hay at or after start, or -1.
findReturns the offset of the first needle in hay, or -1.
rfindReturns the offset of the last needle in hay, or -1.
containsReturns true when needle occurs in hay.
starts_withReturns true when buf begins with prefix.
ends_withReturns true when buf ends with suffix.
copyReturns a new buffer with the same bytes as src.
replaceReturns a copy of hay with every non-overlapping old replaced by new, left to right.
repeatReturns src repeated n times (empty when n <= 0).
pad_leftReturns src with fill bytes added in front until it is width long; a longer src is returned unchanged.
pad_rightReturns src with fill bytes added at the end until it is width long; a longer src is returned unchanged.
to_stringDecodes b as UTF-8.
from_stringReturns the UTF-8 bytes of s; the same as string::to_bytes.
↑ ↓ navigate ↵ open