use chumsky::prelude::*;
use crate::{
parsers::{runway_number, some_whitespace},
traits::Parsable,
};
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum WindshearWarnings {
AllRunways,
SpecificRunways(Vec<WindshearGroup>),
}
impl Parsable for WindshearWarnings {
fn parser<'src>() -> impl Parser<'src, &'src str, Self, extra::Err<crate::MetarError<'src>>> {
choice((
just("WS ALL RWY").map(|_| WindshearWarnings::AllRunways),
WindshearGroup::parser()
.separated_by(some_whitespace())
.collect::<Vec<_>>()
.map(WindshearWarnings::SpecificRunways),
))
}
}
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WindshearGroup {
pub runway_number: String,
}
impl Parsable for WindshearGroup {
fn parser<'src>() -> impl Parser<'src, &'src str, Self, extra::Err<crate::MetarError<'src>>> {
group((
just("WS"),
text::inline_whitespace().at_least(1),
runway_number(),
))
.map(|(_, (), runway_number)| WindshearGroup { runway_number })
}
}