book_cookbook_number/book_cookbook_number.rs
1use trivet::{ParseResult, Tools};
2
3pub fn main() -> ParseResult<()> {
4 let tools = Tools::new();
5
6 // Parse floats in various bases.
7 assert_eq!(tools.parse_f64("0.525")?, 0.525);
8 assert_eq!(tools.parse_f64("+0x0.82")?, 0.5078125);
9 assert_eq!(tools.parse_f64("-0b0.1e-2")?, -0.125);
10
11 // Parse some integers. Only 128-bit signed and unsigned integers are parsed by tools
12 // at present, and leading plus signs (`+`) are not allowed.
13 assert_eq!(tools.parse_u128("101")?, 101);
14 assert_eq!(tools.parse_u128("0x101")?, 257);
15 assert_eq!(tools.parse_i128("-101")?, -101);
16 Ok(())
17}