diff options
Diffstat (limited to 'aero-ical')
-rw-r--r-- | aero-ical/src/lib.rs | 2 | ||||
-rw-r--r-- | aero-ical/src/prune.rs | 63 |
2 files changed, 40 insertions, 25 deletions
diff --git a/aero-ical/src/lib.rs b/aero-ical/src/lib.rs index 696010a..3f6f633 100644 --- a/aero-ical/src/lib.rs +++ b/aero-ical/src/lib.rs @@ -4,5 +4,5 @@ /// the goal will be to rewrite it in the end so it better /// integrates into Aerogramme pub mod parser; -pub mod query; pub mod prune; +pub mod query; diff --git a/aero-ical/src/prune.rs b/aero-ical/src/prune.rs index d04f700..3eb50ca 100644 --- a/aero-ical/src/prune.rs +++ b/aero-ical/src/prune.rs @@ -1,40 +1,55 @@ -use icalendar::parser::{Component, Property}; use aero_dav::caltypes as cal; +use icalendar::parser::{Component, Property}; pub fn component<'a>(src: &'a Component<'a>, prune: &cal::Comp) -> Option<Component<'a>> { if src.name.as_str() != prune.name.as_str() { - return None + return None; } let name = src.name.clone(); let properties = match &prune.prop_kind { - None => vec![], - Some(cal::PropKind::AllProp) => src.properties.clone(), - Some(cal::PropKind::Prop(l)) => src.properties.iter().filter_map(|prop| { - let sel_filt = match l.iter().find(|filt| filt.name.0.as_str() == prop.name.as_str()) { - Some(v) => v, - None => return None - }; + Some(cal::PropKind::AllProp) | None => src.properties.clone(), + Some(cal::PropKind::Prop(l)) => src + .properties + .iter() + .filter_map(|prop| { + let sel_filt = match l + .iter() + .find(|filt| filt.name.0.as_str() == prop.name.as_str()) + { + Some(v) => v, + None => return None, + }; - match sel_filt.novalue { - None | Some(false) => Some(prop.clone()), - Some(true) => Some(Property { - name: prop.name.clone(), - params: prop.params.clone(), - val: "".into() - }), - } - }).collect::<Vec<_>>(), + match sel_filt.novalue { + None | Some(false) => Some(prop.clone()), + Some(true) => Some(Property { + name: prop.name.clone(), + params: prop.params.clone(), + val: "".into(), + }), + } + }) + .collect::<Vec<_>>(), }; let components = match &prune.comp_kind { - None => vec![], - Some(cal::CompKind::AllComp) => src.components.clone(), - Some(cal::CompKind::Comp(many_inner_prune)) => src.components.iter().filter_map(|src_component| { - many_inner_prune.iter().find_map(|inner_prune| component(src_component, inner_prune)) - }).collect::<Vec<_>>(), + Some(cal::CompKind::AllComp) | None => src.components.clone(), + Some(cal::CompKind::Comp(many_inner_prune)) => src + .components + .iter() + .filter_map(|src_component| { + many_inner_prune + .iter() + .find_map(|inner_prune| component(src_component, inner_prune)) + }) + .collect::<Vec<_>>(), }; - Some(Component { name, properties, components }) + Some(Component { + name, + properties, + components, + }) } |