joto_parse

Crates.iojoto_parse
lib.rsjoto_parse
version0.1.1
created_at2025-08-25 01:47:08.1894+00
updated_at2025-09-10 00:08:46.231714+00
descriptionFast, const-safe parser for SI, US Customary, and typesetting dimensions with exact representation.
homepage
repositoryhttps://github.com/xorgy/joto
max_upload_size
id1808966
size95,363
Aaron Muir Hamilton (xorgy)

documentation

README

Joto Parse

What's in a number?

dependency status ISC/MIT/Apache 2.0 Build status Crates.io Docs

This package contains const-safe, allocation-free parsing of mixed units into iota for working with other joto workspace packages.

In this workspace, IOTA is defined as one ninth of a nanometer. This allows common fractions of an inch (ten-thousandths, desktop publishing points, and sixty-fourths) and nanometers to be represented as integers. Using this base unit, combinations of lengths in either US customary units or SI units can be added, subtracted, and multiplied without loss of precision.

Examples

Basic usage

use joto_constants::length::u64::{FOOT, INCH, MILLIMETER, SIXTY_FOURTH};
use joto_parse::u64::parse_dim;

assert_eq!(parse_dim("2.5cm").unwrap(), 25 * MILLIMETER);
assert_eq!(parse_dim("46'1137⁄64\"").unwrap(), 46 * FOOT + 11 * INCH + 37 * SIXTY_FOURTH);

Invertibility

Invertibility is the primary attraction of iota as a base unit. You can add and subtract mixed units with iota, and by extension joto, without loss.

use joto_parse::u128::parse_dim;

fn p(s: impl AsRef<str>) -> u128 {
    parse_dim(s.as_ref()).unwrap()
}

assert_eq!(0, p("2.5cm") + p("1⁄64in") + p("0.500 in") - p("37,700μm") - p("1/64″"));

Constant evaluation

The parsing functions are all const, so can be used for compile-time constants and statics.

use joto_parse::u128::parse_dim;
use joto_constants::length::u128::{FOOT, INCH, MILLIMETER, SIXTY_FOURTH};

const DIAMETER: u128 = parse_dim("21ft1117⁄32in").unwrap();
assert_eq!(DIAMETER / 2, 10 * FOOT + 11 * INCH + 49 * SIXTY_FOURTH);

Minimum Supported Rust Version (MSRV)

This version of joto_parse has been verified to compile with Rust 1.79 and later.

Future versions might increase the Rust version requirement. It will not be treated as a breaking change, and as such can even happen with small patch releases.

License

Triple licensed, at your option:

Contribution

Contributions are welcome by pull request or email. Please feel free to add your name to the AUTHORS file in any substantive pull request.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

Commit count: 4

cargo fmt