Lines
99.31 %
Functions
69.23 %
Branches
100 %
use std::fmt::{Display, Formatter};
#[derive(Clone, PartialEq, Debug)]
pub enum ICalendarErrorSeverity {
/// Invalid according to the iCalendar specification.
Error,
/// Non-fatal issue that could be fixed but can be ignored.
///
/// For example, redundant VALUE parameters or unnecessary WKST properties in an RRULE.
Warning,
}
#[derive(Clone)]
pub struct ICalendarError {
pub message: String,
pub severity: ICalendarErrorSeverity,
pub location: Option<ICalendarLocation>,
impl Display for ICalendarError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if let Some(location) = &self.location {
match location {
ICalendarLocation::CalendarProperty(cp) => {
write!(
f,
"In calendar property \"{}\" at index {}",
cp.name, cp.index
)?;
ICalendarLocation::Component(component) => {
"In component \"{}\" at index {}",
component.name, component.index
if let Some(within) = &component.location {
match &**within {
WithinComponentLocation::Property(cp) => {
", in component property \"{}\" at index {}",
WithinComponentLocation::Component(nested_component_location) => {
", in nested component \"{}\" at index {}",
nested_component_location.name, nested_component_location.index
if let Some(nested_within) = &nested_component_location.location {
if let WithinComponentLocation::Property(cp) = &**nested_within
{
", in nested component property \"{}\" at index {}",
write!(f, ": {}", self.message)
} else {
write!(f, "{}", self.message)
impl ICalendarError {
pub(super) fn many_from_calendar_property_errors(
errors: Vec<CalendarPropertyError>,
) -> Vec<Self> {
errors
.into_iter()
.map(|error| ICalendarError {
message: error.message,
severity: error.severity,
location: error.location.map(ICalendarLocation::CalendarProperty),
})
.collect()
pub(super) fn many_from_component_property_errors(
errors: Vec<ComponentPropertyError>,
index: usize,
name: String,
location: Some(ICalendarLocation::Component(ComponentLocation {
index,
name: name.clone(),
location: error
.location
.map(|l| Box::new(WithinComponentLocation::Property(l))),
})),
pub(super) fn many_from_nested_component_property_errors(
nested_index: usize,
nested_name: String,
location: Some(
WithinComponentLocation::Component(ComponentLocation {
index: nested_index,
name: nested_name.clone(),
.into(),
),
pub enum ICalendarLocation {
CalendarProperty(CalendarPropertyLocation),
Component(ComponentLocation),
pub struct ComponentLocation {
pub index: usize,
pub name: String,
pub location: Option<Box<WithinComponentLocation>>,
pub enum WithinComponentLocation {
Property(ComponentPropertyLocation),
pub struct CalendarPropertyError {
pub location: Option<CalendarPropertyLocation>,
impl CalendarPropertyError {
pub(super) fn many_from_param_errors(
errors: Vec<ParamError>,
.map(|error| CalendarPropertyError {
location: Some(CalendarPropertyLocation {
property_location: Some(WithinPropertyLocation::Param {
index: error.index,
name: error.name,
}),
pub struct CalendarPropertyLocation {
pub property_location: Option<WithinPropertyLocation>,
pub struct ComponentPropertyError {
pub location: Option<ComponentPropertyLocation>,
impl ComponentPropertyError {
.map(|error| ComponentPropertyError {
location: Some(ComponentPropertyLocation {
pub struct ComponentPropertyLocation {
pub enum WithinPropertyLocation {
Param { index: usize, name: String },
Value,
pub struct ParamError {