si
si
A module for parsing, converting, and formatting physical quantities expressed in the International System of Units.
# Parsing
# Formatting
Index
Types
type dimension;
type encoding;
type notation;
type quantity;
type unit;
type unexpected;
Errors
type dimension_mismatch;
type divide_by_zero;
type error;
type invalid;
type invalid_exponent;
type no_match;
type not_implemented;
type unexpected_token;
Globals
const GIT_VERSION: str;
const SEM_VERSION: str;
Functions
fn div(a: unit, b: unit) (unit | divide_by_zero);
fn encodejson(out: io::handle, obj: (quantity | unit)) (size | error);
fn fprintq(h: io::handle, qty: quantity, unit_format: (str | void) = void, prec: (uint | void) = void, repr: notation = notation::GENERAL, enc: encoding = encoding::UTF8) (size | error);
fn fprintu(h: io::handle, u: unit) (size | error);
fn mul(a: unit, b: unit) unit;
fn pow_unit(a: unit, exp: int) unit;
fn tojson(obj: (quantity | unit)) (str | error);
fn count(s: str) size;
fn fprintqln(h: io::handle, qty: quantity, unit_format: (str | void) = void, prec: (uint | void) = void, repr: notation = notation::GENERAL, enc: encoding = encoding::UTF8) (size | error);
fn fprintuln(h: io::handle, u: unit) (size | error);
fn parse(s: str) (quantity | error);
fn printerror(err: error) (void | io::error);
fn strerror(err: error) str;
Types
type dimension
type dimension = struct {
mass: int,
length: int,
time: int,
current: int,
temperature: int,
substance: int,
luminosity: int,
};
Represents the dimensional exponents of the seven SI base dimensions.
type encoding
type encoding = enum u8 {
ASCII,
UTF8,
JSON,
};
Specifies the character encoding options.
type notation
type notation = enum u8 {
GENERAL,
FIXED,
SCIENTIFIC,
E_UPPER,
E_LOWER,
};
Specifies the notation used to format floating-point values.
type quantity
type quantity = struct {
unit: unit,
value: f64,
};
Represents a physical quantity as a unit and numerical value.
type unit
type unit = struct {
dim: dimension,
scale: f64,
};
Represents a unit of measurement by its physical dimension and scale.
type unexpected
Show undocumented member
type unexpected = struct {
pos: size,
exp: str,
got: str,
};
Errors
type dimension_mismatch
Show undocumented member
type dimension_mismatch = !void;
type divide_by_zero
Show undocumented member
type divide_by_zero = !void;
type error
Show undocumented member
type error = !(no_match | divide_by_zero | invalid_exponent | dimension_mismatch | unexpected_token | not_implemented | invalid | io::error | strconv::invalid | strconv::overflow | utf8::invalid | nomem);
type invalid
Show undocumented member
type invalid = !void;
type invalid_exponent
Show undocumented member
type invalid_exponent = !rune;
type no_match
Show undocumented member
type no_match = !str;
type not_implemented
Show undocumented member
type not_implemented = !str;
type unexpected_token
Show undocumented member
type unexpected_token = !rune;
Globals
let GIT_VERSION
Show undocumented member
const GIT_VERSION: str;
let SEM_VERSION
Show undocumented member
const SEM_VERSION: str;
Functions
fn div
fn div(a: unit, b: unit) (unit | divide_by_zero);
Returns the quotiant of a and b.
fn encodejson
fn encodejson(out: io::handle, obj: (quantity | unit)) (size | error);
Writes JSON encoded representation of a quantity or unit.
fn fprintq
fn fprintq(h: io::handle, qty: quantity, unit_format: (str | void) = void, prec: (uint | void) = void, repr: notation = notation::GENERAL, enc: encoding = encoding::UTF8) (size | error);
Prints a quantity to stdout.
fn fprintu
fn fprintu(h: io::handle, u: unit) (size | error);
Prints a unit to stdout.
fn mul
fn mul(a: unit, b: unit) unit;
Returns the product of a and b.
fn pow_unit
fn pow_unit(a: unit, exp: int) unit;
Returns the value of a raised to the power of b.
fn tojson
fn tojson(obj: (quantity | unit)) (str | error);
Returns JSON encoded string representation of a quantity or unit.
fn count
Show undocumented member
fn count(s: str) size;
fn fprintqln
Show undocumented member
fn fprintqln(h: io::handle, qty: quantity, unit_format: (str | void) = void, prec: (uint | void) = void, repr: notation = notation::GENERAL, enc: encoding = encoding::UTF8) (size | error);
fn fprintuln
Show undocumented member
fn fprintuln(h: io::handle, u: unit) (size | error);
fn parse
Show undocumented member
fn parse(s: str) (quantity | error);
fn printerror
Show undocumented member
fn printerror(err: error) (void | io::error);
fn strerror
Show undocumented member
fn strerror(err: error) str;