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 {
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 {
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 {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
unimplemented!();
}
}
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!();
xml.write_event_async(Event::Start(start.clone())).await?;
self.0.write(xml, ctx.child()).await?;
xml.write_event_async(Event::End(end)).await
}
}
impl<C: CalContext> QuickWritable<C> for TimeRange {
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
/// error response.
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)>
/// PCDATA value: iCalendar object
@ -1328,7 +1311,7 @@ pub enum ParamFilterMatch {
///
/// <!ELEMENT timezone (#PCDATA)>
/// PCDATA value: an iCalendar object with exactly one VTIMEZONE
pub struct TimeZone(String);
pub struct TimeZone(pub String);
/// Name: filter
///
@ -1343,7 +1326,24 @@ pub struct TimeZone(String);
///
/// Definition:
/// <!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
pub enum Component {
@ -1382,17 +1382,19 @@ impl PropertyParameter {
}
}
/// 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>),
#[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(),
}
}
}