hex
import std::encoding::hex; · source
Free Functions
function encode(bytes: &Slice<u8>) -> String;
function encode(bytes: &Slice<u8>) -> String;bytes as lowercase hexadecimal, two digits per byte.
Two lowercase digits per byte, most significant nibble first: [0x0f, 0xa0] is 0fa0.
import std::encoding::hex;
const digest: Str = "hi";
const text: String = hex::encode(digest.as_bytes()); // "6869"
Constants
const DIGITS: string = "0123456789abcdef";import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
namespace std::encoding::hex;Hexadecimal text for bytes: two lowercase digits per byte, most significant nibble first ([0x0f, 0xa0] is 0fa0).
const NAME: Type = value;At module level, a true compile-time constant, conventionally SCREAMING_SNAKE_CASE. (mut at module level declares mutable global state instead.)
const digest: Strtype struct Str {}A read-only view of UTF-8 text owned elsewhere: a string literal, a String, a file's bytes. Copying a Str copies the view, not the text, and it is valid only while what it views is. Str::new("text") views a literal; String.as_str() views a String.
const text: Stringtype struct String<A = GlobalAllocator> {}Owned, growable UTF-8 text. It dereferences to Str, the read-only view most text functions take, so every Str method reads a String too (s.contains(...), s.split(...)); as_str hands the view out.
function encode(bytes: &Slice<u8>) -> Stringbytes as lowercase hexadecimal, two digits per byte.
const digest: StrStr::as_bytes(&this) -> &Slice<u8>Underlying byte view. Use this for byte-granularity algorithms (hashing, equality, substring search).
std::collections::strconst DIGITS: string = "0123456789abcdef";primitive stringNUL-terminated raw string (u8*), matching the C ABI. Length-typed text is Str / String.
function name<T>(param: Type) -> Ret { ... }Declares a function. Parameters are written name: Type and are never inferred; the return type follows -> and defaults to void. Declaration order does not matter: every signature is collected before any body is checked, so functions may call each other freely and recurse.
function encode(bytes: &Slice<u8>) -> Stringbytes as lowercase hexadecimal, two digits per byte.
(parameter) bytes: &Slice<u8>type struct Slice<T> {}The elements are reached through ptr, declared read-only: through a mut &Slice<T> it reads as a writable pointer, through a &Slice<T> as the read-only one it is.