bytes

bytes

Binary bytes builtin namespace.

Runtime support: native and WebAssembly.

Import

use bytes;

Functions

FunctionDescription
from_utf8Encodes a string as UTF-8 bytes.
to_utf8Decodes UTF-8 bytes into a string.
to_utf8_lossyDecodes bytes into a string using UTF-8 replacement semantics.
from_hexDecodes a hexadecimal string into bytes.
to_hexEncodes bytes as lowercase hexadecimal.
from_base64Decodes a base64 string into bytes.
to_base64Encodes bytes as standard base64.
from_array_u8Converts an array of ints in 0..=255 into bytes.
to_array_u8Converts bytes into an array of ints in 0..=255.

Function details

from_utf8

fn from_utf8(text: string) -> bytes

Encodes a string as UTF-8 bytes.

to_utf8

fn to_utf8(payload: bytes) -> string

Decodes UTF-8 bytes into a string.

to_utf8_lossy

fn to_utf8_lossy(payload: bytes) -> string

Decodes bytes into a string using UTF-8 replacement semantics.

from_hex

fn from_hex(text: string) -> bytes

Decodes a hexadecimal string into bytes.

to_hex

fn to_hex(payload: bytes) -> string

Encodes bytes as lowercase hexadecimal.

from_base64

fn from_base64(text: string) -> bytes

Decodes a base64 string into bytes.

to_base64

fn to_base64(payload: bytes) -> string

Encodes bytes as standard base64.

from_array_u8

fn from_array_u8(values: array) -> bytes

Converts an array of ints in 0..=255 into bytes.

to_array_u8

fn to_array_u8(payload: bytes) -> array

Converts bytes into an array of ints in 0..=255.