base64
import std::encoding::base64; · source
Free Functions
Base64
RFC 4648, standard alphabet, with padding.
import std::encoding::base64;
mut text: String = encode(bytes.as_ptr(), bytes.length());
match (decode(text.as_str())) {
Option::Some(raw) => { /* Array<u8> */ }
Option::None => { /* malformed input */ }
}
encode encodes len bytes into a padded base64 string you own.
decode returns None on any invalid character or a malformed length. Whitespace is not tolerated — strip line breaks before calling if the input came from a wrapped MIME body.
function encode(data: u8*, len: u64) -> String;
function encode(data: u8*, len: u64) -> String;Encode len bytes at data to a padded base64 String.
function decode(source: Str) -> Option<Array<u8>>;
function decode(source: Str) -> Option<Array<u8>>;Decode a base64 Str. Returns None on any invalid character or a malformed length. Whitespace is not tolerated.
Constants
const PAD: u8 = 0x3D;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).
mut name: Type = value;A mutable binding, reassignable after declaration - mutability is opt-in, const is the default. At module level it declares mutable global state. Before & it marks an exclusive reference or receiver instead.
mut text: Stringtype struct String<A = GlobalAlloc> {
buffer: RawBuffer<u8, A>;
length: u64;
}String: owned, heap-allocated, length-typed UTF-8.
std::collections::stringfunction encode(data: u8*, len: u64) -> StringEncode len bytes at data to a padded base64 String.
match (subject) {
Pattern(x) => { ... }
_ => { ... }
}The primary discriminator: branches on enum variants, integers, ranges, and destructuring patterns, and the compiler rejects a match that misses a case. There is no fallthrough. As an expression it evaluates to the chosen arm's value, so every arm must produce the same type.
function decode(source: Str) -> Option<Array<u8>>Decode a base64 Str. Returns None on any invalid character or a malformed length. Whitespace is not tolerated.
mut text: StringString::as_str(&this) -> StrBorrow as a Str. Invalidated by the next mutating call.
Option::Some(T)raw: Array<u8>pattern => { body }Separates a match arm's pattern from its body. Arms do not fall through.
Option::Noneconst 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 PAD: u8 = 0x3D;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(data: u8*, len: u64) -> StringEncode len bytes at data to a padded base64 String.
(parameter) data: u8*(parameter) len: u64function decode(source: Str) -> Option<Array<u8>>Decode a base64 Str. Returns None on any invalid character or a malformed length. Whitespace is not tolerated.
(parameter) source: Strtype struct Str {
bytes: u8*;
length: u64;
}Str: a borrowed UTF-8 string slice.
std::collections::strtype struct Array<T, A = GlobalAlloc> where A: Allocator {
ptr: T*;
length: i64;
capacity: i64;
alloc: A;
}Array<T, A>: growable, heap-backed, contiguous sequence.
std::collections::array