Module std::encoding::hex

Hexadecimal encoding and decoding.

Encode binary data to hexadecimal strings (lowercase or uppercase) and decode hexadecimal strings back to binary data.

Examples

import std::encoding::hex;

fn main() {
    let data: bytes = bytes::new();
    data.push(0xDE);
    data.push(0xAD);
    let s = hex.encode(data);
    println(s);   // "dead"
    let back = hex.decode(s);
    println(back.len());  // 2
}

Contents

Functions

Function encode

pub fn encode(data: bytes) -> string

Encode binary data to a lowercase hex string.

Function encode_upper

pub fn encode_upper(data: bytes) -> string

Encode binary data to an uppercase hex string.

Function decode

pub fn decode(s: string) -> bytes

Decode a hex string to binary data.

Returns an empty bytes buffer if the input is not valid hex.