asterix_parser 0.1.1

Playground do Protocolo ASTERIX
Documentation
use chrono::NaiveDate;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum ParseDateError {
    #[error("bad argumens provided for parsing the date attribute")]
    BadArgumentsProvided,
}

fn parse_date(year: i32, month:u32, day: u32) -> anyhow::Result<NaiveDate> {
    let date = match NaiveDate::from_ymd_opt(year, month, day) {
        Some(d) => d,
        None => return Err(ParseDateError::BadArgumentsProvided.into()),
    };

    Ok(date)
}

#[test]
pub fn test_thiserror() {
    println!("Hello, world!");
    let date = match parse_date(2024, 13, 11) {
        Ok(n) => n,
        Err(e) => {
            println!("Bad result: {:?}", e);
            return;
        }
    };
    println!("{}", date);
}