Module mag::length

source · []
Expand description

Units of length in one dimension.

Each unit is defined relative to meters with a conversion factor. They can be used to conveniently create Length, Area and Volume structs.

Example

use mag::length::{cm, m, mi, yd};

let a = 25.5 * cm; // Length<cm>
let b = 5.6 * mi; // Length<mi>
let c = 1.2 * m * m; // Area<m>
let d = 5.259 * yd * yd * yd; // Volume<yd>
// let e = 1 * m * mi; // ERROR: units must match!

assert_eq!(a.to_string(), "25.5 cm");
assert_eq!(b.to_string(), "5.6 mi");
assert_eq!(c.to_string(), "1.2 m²");
assert_eq!(format!("{:.2}", d), "5.26 yd³");

Structs

Inch (capitalized to avoid clashing with in keyword)

Centimeter / Centimetre

Decimeter / Decimetre

Fathom (6 ft)

Foot (international)

Furlong (220 yd)

Kilometer / Kilometre

League (3 mi)

Meter / Metre

Mile

Millimeter / Millimetre

Nanometer / Nanometre

Rod (16.5 ft)

Micrometer / Micrometre

Yard (international)

Traits

Unit definition for Length