Sha256: 06647d68a57f8ef47198bda81dd88b2e123e70c7e1a79a0109a759ead1212904

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 KB

Contents

use winnow::prelude::*;

mod parser;

use parser::hex_color;

fn main() -> Result<(), lexopt::Error> {
    let args = Args::parse()?;

    let input = args.input.as_deref().unwrap_or("#AAAAAA");

    println!("{input} =");
    match hex_color.parse(input) {
        Ok(result) => {
            println!("  {result:?}");
        }
        Err(err) => {
            println!("  {err}");
        }
    }

    Ok(())
}

#[derive(Default)]
struct Args {
    input: Option<String>,
}

impl Args {
    fn parse() -> Result<Self, lexopt::Error> {
        use lexopt::prelude::*;

        let mut res = Args::default();

        let mut args = lexopt::Parser::from_env();
        while let Some(arg) = args.next()? {
            match arg {
                Value(input) => {
                    res.input = Some(input.string()?);
                }
                _ => return Err(arg.unexpected()),
            }
        }
        Ok(res)
    }
}

#[test]
fn parse_color() {
    assert_eq!(
        hex_color.parse_peek("#2F14DF"),
        Ok((
            "",
            parser::Color {
                red: 47,
                green: 20,
                blue: 223,
            }
        ))
    );
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/winnow-0.6.24/examples/css/main.rs
wasmtime-28.0.0 ./ext/cargo-vendor/winnow-0.6.22/examples/css/main.rs
wasmtime-27.0.0 ./ext/cargo-vendor/winnow-0.6.20/examples/css/main.rs
wasmtime-26.0.0 ./ext/cargo-vendor/winnow-0.6.20/examples/css/main.rs
wasmtime-25.0.2 ./ext/cargo-vendor/winnow-0.6.18/examples/css/main.rs
wasmtime-25.0.1 ./ext/cargo-vendor/winnow-0.6.18/examples/css/main.rs
wasmtime-25.0.0 ./ext/cargo-vendor/winnow-0.6.18/examples/css/main.rs
wasmtime-24.0.0 ./ext/cargo-vendor/winnow-0.6.18/examples/css/main.rs