Crates.io | joto_parse |
lib.rs | joto_parse |
version | 0.1.1 |
created_at | 2025-08-25 01:47:08.1894+00 |
updated_at | 2025-09-10 00:08:46.231714+00 |
description | Fast, const-safe parser for SI, US Customary, and typesetting dimensions with exact representation. |
homepage | |
repository | https://github.com/xorgy/joto |
max_upload_size | |
id | 1808966 |
size | 95,363 |
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.
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 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″"));
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);
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.
Triple licensed, at your option:
ISC license (LICENSE-ISC)
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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.