CalEncoder should be fully implemented now

This commit is contained in:
Quentin 2024-03-03 11:08:00 +01:00
parent 433e1f97f6
commit 463be750e1
Signed by: quentin
GPG Key ID: E9602264D639FF68
2 changed files with 56 additions and 53 deletions

View File

@ -638,37 +638,38 @@ impl<C: CalContext> QuickWritable<C> for ParamFilterMatch {
impl<C: CalContext> QuickWritable<C> for TimeZone { impl<C: CalContext> QuickWritable<C> for TimeZone {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!(); let mut start = ctx.create_cal_element("timezone");
let end = start.to_end();
xml.write_event_async(Event::Start(start.clone())).await?;
xml.write_event_async(Event::Text(BytesText::new(self.0.as_str()))).await?;
xml.write_event_async(Event::End(end)).await
} }
} }
impl<C: CalContext> QuickWritable<C> for Filter { impl<C: CalContext> QuickWritable<C> for Filter {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!(); let mut start = ctx.create_cal_element("filter");
} let end = start.to_end();
}
impl<C: CalContext> QuickWritable<C> for Component { xml.write_event_async(Event::Start(start.clone())).await?;
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { self.0.write(xml, ctx.child()).await?;
unimplemented!(); xml.write_event_async(Event::End(end)).await
}
}
impl<C: CalContext> QuickWritable<C> for ComponentProperty {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!();
}
}
impl<C: CalContext> QuickWritable<C> for PropertyParameter {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!();
} }
} }
impl<C: CalContext> QuickWritable<C> for TimeRange { impl<C: CalContext> QuickWritable<C> for TimeRange {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!(); let mut empty = ctx.create_cal_element("time-range");
match self {
Self::OnlyStart(start) => empty.push_attribute(("start", format!("{}", start.format(ICAL_DATETIME_FMT)).as_str())),
Self::OnlyEnd(end) => empty.push_attribute(("end", format!("{}", end.format(ICAL_DATETIME_FMT)).as_str())),
Self::FullRange(start, end) => {
empty.push_attribute(("start", format!("{}", start.format(ICAL_DATETIME_FMT)).as_str()));
empty.push_attribute(("end", format!("{}", end.format(ICAL_DATETIME_FMT)).as_str()));
}
}
xml.write_event_async(Event::Empty(empty)).await
} }
} }

View File

@ -771,23 +771,6 @@ pub enum Violation {
/// server MUST respond with a CALDAV:supported-collation precondition /// server MUST respond with a CALDAV:supported-collation precondition
/// error response. /// error response.
pub struct SupportedCollation(pub Collation); pub struct SupportedCollation(pub Collation);
#[derive(Default)]
pub enum Collation {
#[default]
AsciiCaseMap,
Octet,
Unknown(String),
}
impl Collation {
pub fn as_str<'a>(&'a self) -> &'a str {
match self {
Self::AsciiCaseMap => "i;ascii-casemap",
Self::Octet => "i;octet",
Self::Unknown(c) => c.as_str(),
}
}
}
/// <!ELEMENT calendar-data (#PCDATA)> /// <!ELEMENT calendar-data (#PCDATA)>
/// PCDATA value: iCalendar object /// PCDATA value: iCalendar object
@ -1328,7 +1311,7 @@ pub enum ParamFilterMatch {
/// ///
/// <!ELEMENT timezone (#PCDATA)> /// <!ELEMENT timezone (#PCDATA)>
/// PCDATA value: an iCalendar object with exactly one VTIMEZONE /// PCDATA value: an iCalendar object with exactly one VTIMEZONE
pub struct TimeZone(String); pub struct TimeZone(pub String);
/// Name: filter /// Name: filter
/// ///
@ -1343,7 +1326,24 @@ pub struct TimeZone(String);
/// ///
/// Definition: /// Definition:
/// <!ELEMENT filter (comp-filter)> /// <!ELEMENT filter (comp-filter)>
pub struct Filter(CompFilter); pub struct Filter(pub CompFilter);
/// Name: time-range
///
/// Definition:
///
/// <!ELEMENT time-range EMPTY>
/// <!ATTLIST time-range start CDATA #IMPLIED
/// end CDATA #IMPLIED>
/// start value: an iCalendar "date with UTC time"
/// end value: an iCalendar "date with UTC time"
pub enum TimeRange {
OnlyStart(DateTime<Utc>),
OnlyEnd(DateTime<Utc>),
FullRange(DateTime<Utc>, DateTime<Utc>),
}
// ----------------------- ENUM ATTRIBUTES ---------------------
/// Known components /// Known components
pub enum Component { pub enum Component {
@ -1355,7 +1355,7 @@ pub enum Component {
VAlarm, VAlarm,
Unknown(String), Unknown(String),
} }
impl Component { impl Component {
pub fn as_str<'a>(&'a self) -> &'a str { pub fn as_str<'a>(&'a self) -> &'a str {
match self { match self {
Self::VCalendar => "VCALENDAR", Self::VCalendar => "VCALENDAR",
@ -1382,17 +1382,19 @@ impl PropertyParameter {
} }
} }
/// Name: time-range #[derive(Default)]
/// pub enum Collation {
/// Definition: #[default]
/// AsciiCaseMap,
/// <!ELEMENT time-range EMPTY> Octet,
/// <!ATTLIST time-range start CDATA #IMPLIED Unknown(String),
/// end CDATA #IMPLIED> }
/// start value: an iCalendar "date with UTC time" impl Collation {
/// end value: an iCalendar "date with UTC time" pub fn as_str<'a>(&'a self) -> &'a str {
pub enum TimeRange { match self {
OnlyStart(DateTime<Utc>), Self::AsciiCaseMap => "i;ascii-casemap",
OnlyEnd(DateTime<Utc>), Self::Octet => "i;octet",
FullRange(DateTime<Utc>, DateTime<Utc>), Self::Unknown(c) => c.as_str(),
}
}
} }