use crate::parser::ast::Section;
use alloc::string::String;
#[derive(Debug, Clone)]
pub enum ParseDelta<'a> {
AddSection(Section<'a>),
UpdateSection(usize, Section<'a>),
RemoveSection(usize),
ParseIssue(String),
}
impl<'a> ParseDelta<'a> {
#[must_use]
pub const fn add_section(section: Section<'a>) -> Self {
Self::AddSection(section)
}
#[must_use]
pub const fn update_section(index: usize, section: Section<'a>) -> Self {
Self::UpdateSection(index, section)
}
#[must_use]
pub const fn remove_section(index: usize) -> Self {
Self::RemoveSection(index)
}
#[must_use]
pub const fn parse_issue(message: String) -> Self {
Self::ParseIssue(message)
}
#[must_use]
pub const fn is_error(&self) -> bool {
matches!(self, Self::ParseIssue(_))
}
#[must_use]
pub const fn is_structural(&self) -> bool {
matches!(
self,
Self::AddSection(_) | Self::UpdateSection(_, _) | Self::RemoveSection(_)
)
}
#[must_use]
pub const fn section(&self) -> Option<&Section<'a>> {
match self {
Self::AddSection(section) | Self::UpdateSection(_, section) => Some(section),
_ => None,
}
}
}