Expand description
Flexible string parsing for num_rational.
This crate provides flexible string parsing for rational numbers, inspired by
Python’s fractions module, allowing num_rational::Ratio to be parsed from
strings with flexible formatting.
§Examples
use num_rational::Ratio;
use num_rational_parse::RationalParse;
let r = Ratio::<i32>::from_str_flex("3.14").unwrap();
assert_eq!(r, Ratio::new(157, 50));
let r2 = Ratio::<i32>::from_str_flex("1.2e-2").unwrap();
assert_eq!(r2, Ratio::new(3, 250));
let r3 = Ratio::<i32>::from_str_flex("-1_000/2_000").unwrap();
assert_eq!(r3, Ratio::new(-1, 2));Structs§
- Parse
Ratio Error - An error which can be returned when parsing a ratio.
Enums§
- Ratio
Error Kind - The specific type of error that occurred during parsing.
Traits§
- Rational
Parse - A trait for parsing a string into a rational number with flexible formats.