Skip to content

bytes

Helpers for byte slices and sizes that the standard library does not provide.

Reading integers at an offset without panicking, a byte-slice search, a constant-time comparison, XOR, and human-readable sizes (1.5 KiB) in both directions.

Cargo feature bytes (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features bytes

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.6", default-features = false, features = ["bytes"] }

Import path: helpers4::bytes.

ItemWhat it does
constant_time_eqCompares two byte slices without stopping at the first difference.
EndianThe byte order of a multi-byte integer.
findThe index of the first occurrence of needle in haystack.
format_sizeFormats a number of bytes with a binary unit and at most one decimal, such as "1.5 KiB".
parse_sizeParses a human-written size such as "1.5 KiB", "10MB" or "512" into a number of bytes.
read_u16Reads a u16 from bytes at offset, in the given byte order.
read_u32Reads a u32 from bytes at offset, in the given byte order.
read_u64Reads a u64 from bytes at offset, in the given byte order.
xorThe bytewise XOR of two slices of the same length.

Documented on the page of the helper that returns them.

TypeReturned by
ParseSizeErrorparse_size