All Projects → paholg → Dimensioned

paholg / Dimensioned

Licence: mit
Compile-time dimensional analysis for various unit systems using Rust's type system.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Dimensioned

fp-units
An FP-oriented library to easily convert CSS units.
Stars: ✭ 18 (-92.34%)
Mutual labels:  conversion, units
physikal
Mirror of Gitlab Repository
Stars: ✭ 33 (-85.96%)
Mutual labels:  conversion, units
cpc
Text calculator with support for units and conversion
Stars: ✭ 89 (-62.13%)
Mutual labels:  conversion, units
Rink Rs
Unit conversion tool and library written in rust
Stars: ✭ 242 (+2.98%)
Mutual labels:  units, conversion
Convert Units
An elegant way to convert quantities between different units.
Stars: ✭ 480 (+104.26%)
Mutual labels:  units, conversion
php-unit-conversion
A library providing full PSR-4 compatible unit conversions
Stars: ✭ 47 (-80%)
Mutual labels:  conversion, units
Unchained
A fully type safe, compile time only units library.
Stars: ✭ 70 (-70.21%)
Mutual labels:  units, type-safety
Units Converter
A simple utility library to measure and convert between units
Stars: ✭ 31 (-86.81%)
Mutual labels:  units, conversion
Js Quantities
JavaScript library for quantity calculation and unit conversion
Stars: ✭ 335 (+42.55%)
Mutual labels:  units, conversion
Length.js
📏 JavaScript library for length units conversion.
Stars: ✭ 292 (+24.26%)
Mutual labels:  units, conversion
Unitsnet
Makes life working with units of measurement just a little bit better.
Stars: ✭ 641 (+172.77%)
Mutual labels:  units, conversion
Coulomb
coulomb: unit analysis for Scala
Stars: ✭ 109 (-53.62%)
Mutual labels:  type-safety, units
Color
A little library to deal with color conversions
Stars: ✭ 166 (-29.36%)
Mutual labels:  conversion
Insect
High precision scientific calculator with support for physical units
Stars: ✭ 2,469 (+950.64%)
Mutual labels:  units
Orm Lite
Header-Only, Strong-Typed, Compile-time Object Relation Mapping (ORM) in Modern C++ :-)
Stars: ✭ 164 (-30.21%)
Mutual labels:  type-safety
Colourful
🎨 Open source .NET library for working with color spaces.
Stars: ✭ 161 (-31.49%)
Mutual labels:  conversion
Percentage
A percentage type for Swift
Stars: ✭ 225 (-4.26%)
Mutual labels:  type-safety
Util
A collection of useful utility functions
Stars: ✭ 201 (-14.47%)
Mutual labels:  conversion
Vue Literal Compiler
A Vue Compiler that allows you compile your string literals to render functions at build time and write components in SFC paradigm
Stars: ✭ 158 (-32.77%)
Mutual labels:  type-safety
Wannabe bool
If string, numeric, symbol and nil values wanna be a boolean value, they can with the new #to_b method (and more).
Stars: ✭ 156 (-33.62%)
Mutual labels:  conversion

crates.io Build Status

Documentation

Dimensioned

A Rust library for compile-time dimensional analysis.

Its goal is to provide zero cost unit safety while requiring minimal effort from the programmer.

Use

Dimensioned requires at least Rust version 1.23.0 (and is tested on this version), although some features may require a newer version.

It does not depend on std; simple include without the default feature std. Doing so requires a nightly version of rustc.

If you are using Rust nightly, then you may enable the "oibit" feature of dimensioned. This will make it work a bit better for wrapping non-primitives in units. The recommended way to use dimensioned is by wrapping only primitives in units, in which case this feature is not helpful.

Contributing

Contributions are welcome! There aren't super strict contributing guidelines, but I have a few requests.

  • Note changes that you make in CHANGELOG.md.
  • Add documentation and tests for anything that you add.
  • Try to keep lists alphabetized in files not addressed by rustfmt.
  • Don't hesitate to prod me if I haven't responded to you in a timely manner. I get busy and forgetful, but I would like to repond to issues and PRs promptly.
  • Feel free to ask questions!

Examples

The Simulation Example provides a simple physics simulation and covers how one can use dimensioned with it in a couple different ways, and what the trade-offs are. If you're curious about what might be involved in adding dimensioned to one of your projects, or what it might look like in semi-real code, then that is the place for you.

The Conversion Example covers how one might implement conversions between unit systems.

Finally, just to get the juices flowing, here's a simple example illustrating some of what dimensioned can do:

extern crate dimensioned as dim;

use dim::{si, cgs};

// Calculates speed given a distance and time. Only works for SI units.
fn speed(dist: si::Meter<f64>, time: si::Second<f64>) -> si::MeterPerSecond<f64> {
    dist / time
}

use std::ops::Div;
use dim::dimensions::{Length, Time};
use dim::typenum::Quot;

// Calculates speed as before, but now we can use *any* unit system.
fn generic_speed<L, T>(dist: L, time: T) -> Quot<L, T>
    where L: Length + Div<T>, T: Time,
{
    dist / time
}

fn main() {
    let si_x = 6.0 * si::M;
    let si_t = 3.0 * si::S;
    let si_v = 2.0 * si::M / si::S;

    let si_v2 = speed(si_x, si_t);
    assert_eq!(si_v, si_v2);

    let cgs_x = 6.0 * cgs::M;
    let cgs_t = 3.0 * cgs::S;
    let cgs_v = 2.0 * cgs::M / cgs::S;

    let cgs_v2 = generic_speed(cgs_x, cgs_t);
    assert_eq!(cgs_v, cgs_v2);

    let si_v3 = cgs_v2.into();
    assert_eq!(si_v2, si_v3);
}

This example is also included as examples/readme-example.rs.

Unit Systems

Dimensioned aims to include unit systems for a large variety of uses. It also includes a make_units! macro to allow you to create any unit system you desire.

Error Messages

Probably the biggest weakness of dimensioned are the error messages generated. The type signatures coming from dimensioned tend to just look like a bunch of gobbly-guck. Someday, we may have a better way to display them.

For now, my advice is that when you get an error message involving dimensioned, just go to the line number and hopefully the issue will be apparant from the code alone.

Friends of dimensioned

If there are any libraries that work particularly well with dimensioned, such as the vector3d library used in part 3 of the simulation example, please let me know and they will be listed here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].