inpt

Crates.ioinpt
lib.rsinpt
version
sourcesrc
created_at2022-09-10 22:37:24.642743
updated_at2024-11-08 05:50:39.117206
descriptionA derive crate for dumb type-level text parsing.
homepage
repositoryhttps://gitlab.com/samsartor/inpt
max_upload_size
id662747
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Sam Sartor (samsartor)

documentation

https://docs.rs/inpt

README

Inpt

Inpt is a derive crate for dumb type-level text parsing.

Read the lastest documentation for more information.

Introduction

Imagine you need to chop up an annoying string and convert all the bits to useful types. You could write that sort of code by hand using split and from_str, but the boiler-plate of unwrapping and checking quickly looses all charm. Especially since that sort of parsing shows up a lot in timed programming competitions like advent of code.

Inpt tries to write that sort of parsing code for you, automatically splitting input strings based on field types and an optional regex. Inpt is absolutely not performant, strict, or formal. Whenever possible, it does the obvious thing:

#[inpt::main]
fn main(x: f32, y: f32) {
    println!("{}", x * y);
}
$ echo '6,7' | cargo run
42

Example

use inpt::{Inpt, inpt};

#[derive(Inpt)]
#[inpt(regex = r"(.)=([-\d]+)\.\.([-\d]+),?")]
struct Axis {
    name: char,
    start: i32,
    end: i32,
}

#[derive(Inpt)]
#[inpt(regex = "target area:")]
struct Target {
    #[inpt(after)]
    axes: Vec<Axis>,
}

impl Target {
    fn area(&self) -> i32 {
        self.axes.iter().map(|Axis { start, end, ..}| end - start).product()
    }
}


let target = inpt::<Target>("target area: x=119..176, y=-114..84").unwrap();
assert_eq!(target.area(), 11286);
Commit count: 45

cargo fmt