hook resource type

This commit is contained in:
Quentin 2024-03-01 10:29:16 +01:00
parent 929a185f37
commit c52a659151
Signed by: quentin
GPG key ID: E9602264D639FF68
3 changed files with 27 additions and 5 deletions

View file

@ -23,6 +23,10 @@ impl Context for CalExtension {
async fn hook_property(&self, prop: &Self::Property, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { async fn hook_property(&self, prop: &Self::Property, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
prop.write(xml, self.child()).await prop.write(xml, self.child()).await
} }
async fn hook_resourcetype(&self, restype: &Self::ResourceType, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
restype.write(xml, self.child()).await
}
} }
impl CalExtension { impl CalExtension {
@ -58,7 +62,13 @@ impl QuickWritable<CalExtension> for Property {
} }
} }
impl QuickWritable<CalExtension> for ResourceType {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: CalExtension) -> Result<(), QError> {
match self {
Self::Calendar => xml.write_event_async(Event::Empty(ctx.create_dav_element("calendar"))).await,
}
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View file

@ -8,7 +8,7 @@ impl Extension for CalExtension {
type Error = Violation; type Error = Violation;
type Property = Property; type Property = Property;
type PropertyRequest = Property; //@FIXME type PropertyRequest = Property; //@FIXME
type ResourceType = Property; //@FIXME type ResourceType = ResourceType;
} }
pub enum Violation { pub enum Violation {
@ -34,3 +34,7 @@ pub enum Property {
CalendarDescription, CalendarDescription,
CalendarTimezone, CalendarTimezone,
} }
pub enum ResourceType {
Calendar,
}

View file

@ -21,6 +21,7 @@ pub trait Context: Extension {
fn create_dav_element(&self, name: &str) -> BytesStart; fn create_dav_element(&self, name: &str) -> BytesStart;
async fn hook_error(&self, err: &Self::Error, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>; async fn hook_error(&self, err: &Self::Error, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>;
async fn hook_property(&self, prop: &Self::Property, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>; async fn hook_property(&self, prop: &Self::Property, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>;
async fn hook_resourcetype(&self, prop: &Self::ResourceType, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError>;
} }
/// -------------- NoExtension Encoding Context /// -------------- NoExtension Encoding Context
@ -41,6 +42,9 @@ impl Context for NoExtension {
async fn hook_property(&self, prop: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> { async fn hook_property(&self, prop: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
unreachable!(); unreachable!();
} }
async fn hook_resourcetype(&self, restype: &Disabled, xml: &mut Writer<impl AsyncWrite+Unpin>) -> Result<(), QError> {
unreachable!();
}
} }
@ -320,13 +324,17 @@ impl<C: Context> QuickWritable<C> for Property<C> {
} }
} }
impl<C: Context> QuickWritable<C> for ActiveLock { impl<C: Context> QuickWritable<C> for ResourceType<C> {
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!(); match self {
Self::Collection => xml.write_event_async(Event::Empty(ctx.create_dav_element("collection"))).await?,
Self::Extension(inner) => ctx.hook_resourcetype(inner, xml).await?,
};
Ok(())
} }
} }
impl<C: Context> QuickWritable<C> for ResourceType<C> { impl<C: Context> QuickWritable<C> for ActiveLock {
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!(); unimplemented!();
} }