dimensioned 0.2.4

Compile-time type checking of arbitrary unit systems.
docs.rs failed to build dimensioned-0.2.4
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: dimensioned-0.8.0

crates.io Build Status

Dimensioned

Note: This library is very much unstable, and you should expect regular breaking changes for now. It also depends on unstable Rust features.

Dimensioned is a library for compile-time type checking of arbitrary unit systems.

To use, place in Cargo.toml:

[dependencies]
  dimensioned = "*"

Note, though, that it is currently going through volatile changes and will stabilize sometime in the future.

Dimensioned now has a convenient macro for creating a unit system. Here is an example of its use (from examples/vec.rs):

make_units! {
    SI, One;
    base {
        Meter, meter, m;
        Kilogram, kilogram, kg;
        Second, second, s;
        Ampere, ampere, A;
        Kelvin, kelvin, K;
        Candela, candela, cd;
        Mole, mole, mol;
    }
    derived {
    }
}

The first line inside the macro, SI, One; is the name of your unit system followed by the highest allowed root that you want in Peano number form. Generally, you want this to be One, but for CGS units, for example, the square root of base units is allowed, so it should be Two. The numbers One through Ten are defined in the library; if for some reason you need something higher, you can use the syntax

type Eleven = Succ<Ten>;

Then, the block base {} designates the base units of the system. They are given in the form Type, constant, print_form; so that the first line, Meter, meter, m; will define the type Meter, the constant meter which is equal to 1f64 m, and when printed will have the m token.

The derived {} block is for derived units. It is not yet implemented, and is only there to ensure future compatibility.

Dimensioned has its own (under construction) website, available here. It is also on Crates.io.