Add ?Sized to CalendarStore generics for dynamic dispatch

This commit is contained in:
Lennart
2023-10-08 14:47:36 +02:00
parent e17e4facd7
commit f6cf5bd645
8 changed files with 21 additions and 18 deletions

View File

@@ -6,14 +6,17 @@ use actix_web::{
use rustical_store::calendar::CalendarStore; use rustical_store::calendar::CalendarStore;
use tokio::sync::RwLock; use tokio::sync::RwLock;
pub fn configure_api<C: CalendarStore>(cfg: &mut web::ServiceConfig, store: Data<RwLock<C>>) { pub fn configure_api<C: CalendarStore + ?Sized>(
cfg: &mut web::ServiceConfig,
store: Data<RwLock<C>>,
) {
cfg.app_data(store).route( cfg.app_data(store).route(
"/{cid}/events", "/{cid}/events",
web::method(Method::GET).to(get_events::<C>), web::method(Method::GET).to(get_events::<C>),
); );
} }
pub async fn get_events<C: CalendarStore>( pub async fn get_events<C: CalendarStore + ?Sized>(
store: Data<RwLock<C>>, store: Data<RwLock<C>>,
path: Path<String>, path: Path<String>,
) -> impl Responder { ) -> impl Responder {

View File

@@ -19,7 +19,7 @@ pub mod proptypes;
pub mod resources; pub mod resources;
pub mod routes; pub mod routes;
pub struct CalDavContext<C: CalendarStore> { pub struct CalDavContext<C: CalendarStore + ?Sized> {
pub prefix: String, pub prefix: String,
pub store: Arc<RwLock<C>>, pub store: Arc<RwLock<C>>,
} }
@@ -28,7 +28,7 @@ pub fn configure_well_known(cfg: &mut web::ServiceConfig, caldav_root: String) {
cfg.service(web::redirect("/caldav", caldav_root).permanent()); cfg.service(web::redirect("/caldav", caldav_root).permanent());
} }
pub fn configure_dav<A: CheckAuthentication, C: CalendarStore>( pub fn configure_dav<A: CheckAuthentication, C: CalendarStore + ?Sized>(
cfg: &mut web::ServiceConfig, cfg: &mut web::ServiceConfig,
prefix: String, prefix: String,
auth: Arc<A>, auth: Arc<A>,

View File

@@ -11,7 +11,7 @@ use tokio::sync::RwLock;
use crate::proptypes::{write_href_prop, write_string_prop}; use crate::proptypes::{write_href_prop, write_string_prop};
use rustical_dav::{resource::Resource, xml_snippets::write_resourcetype}; use rustical_dav::{resource::Resource, xml_snippets::write_resourcetype};
pub struct CalendarResource<C: CalendarStore> { pub struct CalendarResource<C: CalendarStore + ?Sized> {
pub cal_store: Arc<RwLock<C>>, pub cal_store: Arc<RwLock<C>>,
pub calendar: Calendar, pub calendar: Calendar,
pub path: String, pub path: String,
@@ -20,7 +20,7 @@ pub struct CalendarResource<C: CalendarStore> {
} }
#[async_trait(?Send)] #[async_trait(?Send)]
impl<C: CalendarStore> Resource for CalendarResource<C> { impl<C: CalendarStore + ?Sized> Resource for CalendarResource<C> {
type MemberType = Self; type MemberType = Self;
type UriComponents = (String, String); // principal, calendar_id type UriComponents = (String, String); // principal, calendar_id

View File

@@ -9,14 +9,14 @@ use rustical_store::event::Event;
use std::sync::Arc; use std::sync::Arc;
use tokio::sync::RwLock; use tokio::sync::RwLock;
pub struct EventResource<C: CalendarStore> { pub struct EventResource<C: CalendarStore + ?Sized> {
pub cal_store: Arc<RwLock<C>>, pub cal_store: Arc<RwLock<C>>,
pub path: String, pub path: String,
pub event: Event, pub event: Event,
} }
#[async_trait(?Send)] #[async_trait(?Send)]
impl<C: CalendarStore> Resource for EventResource<C> { impl<C: CalendarStore + ?Sized> Resource for EventResource<C> {
type UriComponents = (String, String, String); // principal, calendar, event type UriComponents = (String, String, String); // principal, calendar, event
type MemberType = Self; type MemberType = Self;

View File

@@ -12,7 +12,7 @@ use tokio::sync::RwLock;
use super::calendar::CalendarResource; use super::calendar::CalendarResource;
pub struct PrincipalCalendarsResource<C: CalendarStore> { pub struct PrincipalCalendarsResource<C: CalendarStore + ?Sized> {
prefix: String, prefix: String,
principal: String, principal: String,
path: String, path: String,
@@ -20,7 +20,7 @@ pub struct PrincipalCalendarsResource<C: CalendarStore> {
} }
#[async_trait(?Send)] #[async_trait(?Send)]
impl<C: CalendarStore> Resource for PrincipalCalendarsResource<C> { impl<C: CalendarStore + ?Sized> Resource for PrincipalCalendarsResource<C> {
type UriComponents = (); type UriComponents = ();
type MemberType = CalendarResource<C>; type MemberType = CalendarResource<C>;

View File

@@ -35,7 +35,7 @@ async fn _parse_filter(filter_node: &Node<'_, '_>) {
} }
} }
async fn handle_report_calendar_query<C: CalendarStore>( async fn handle_report_calendar_query<C: CalendarStore + ?Sized>(
query_node: Node<'_, '_>, query_node: Node<'_, '_>,
request: HttpRequest, request: HttpRequest,
events: Vec<Event>, events: Vec<Event>,
@@ -76,7 +76,7 @@ async fn handle_report_calendar_query<C: CalendarStore>(
.body(output)) .body(output))
} }
pub async fn route_report_calendar<A: CheckAuthentication, C: CalendarStore>( pub async fn route_report_calendar<A: CheckAuthentication, C: CalendarStore + ?Sized>(
context: Data<CalDavContext<C>>, context: Data<CalDavContext<C>>,
body: String, body: String,
path: Path<(String, String)>, path: Path<(String, String)>,
@@ -101,7 +101,7 @@ pub async fn route_report_calendar<A: CheckAuthentication, C: CalendarStore>(
handle_report_calendar_query(query_node, request, events, context.store.clone()).await handle_report_calendar_query(query_node, request, events, context.store.clone()).await
} }
pub async fn handle_mkcol_calendar_set<C: CalendarStore>( pub async fn handle_mkcol_calendar_set<C: CalendarStore + ?Sized>(
store: &RwLock<C>, store: &RwLock<C>,
prop_node: Node<'_, '_>, prop_node: Node<'_, '_>,
cid: String, cid: String,
@@ -139,7 +139,7 @@ pub async fn handle_mkcol_calendar_set<C: CalendarStore>(
Ok(()) Ok(())
} }
pub async fn route_mkcol_calendar<A: CheckAuthentication, C: CalendarStore>( pub async fn route_mkcol_calendar<A: CheckAuthentication, C: CalendarStore + ?Sized>(
path: Path<(String, String)>, path: Path<(String, String)>,
body: String, body: String,
auth: AuthInfoExtractor<A>, auth: AuthInfoExtractor<A>,

View File

@@ -23,7 +23,7 @@ impl ResponseError for Error {
} }
} }
pub async fn delete_event<A: CheckAuthentication, C: CalendarStore>( pub async fn delete_event<A: CheckAuthentication, C: CalendarStore + ?Sized>(
context: Data<CalDavContext<C>>, context: Data<CalDavContext<C>>,
path: Path<(String, String, String)>, path: Path<(String, String, String)>,
auth: AuthInfoExtractor<A>, auth: AuthInfoExtractor<A>,
@@ -39,7 +39,7 @@ pub async fn delete_event<A: CheckAuthentication, C: CalendarStore>(
Ok(HttpResponse::Ok().body("")) Ok(HttpResponse::Ok().body(""))
} }
pub async fn get_event<A: CheckAuthentication, C: CalendarStore>( pub async fn get_event<A: CheckAuthentication, C: CalendarStore + ?Sized>(
context: Data<CalDavContext<C>>, context: Data<CalDavContext<C>>,
path: Path<(String, String, String)>, path: Path<(String, String, String)>,
_auth: AuthInfoExtractor<A>, _auth: AuthInfoExtractor<A>,
@@ -56,7 +56,7 @@ pub async fn get_event<A: CheckAuthentication, C: CalendarStore>(
.body(event.get_ics())) .body(event.get_ics()))
} }
pub async fn put_event<A: CheckAuthentication, C: CalendarStore>( pub async fn put_event<A: CheckAuthentication, C: CalendarStore + ?Sized>(
context: Data<CalDavContext<C>>, context: Data<CalDavContext<C>>,
path: Path<(String, String, String)>, path: Path<(String, String, String)>,
body: String, body: String,

View File

@@ -66,7 +66,7 @@ fn parse_propfind(body: &str) -> Result<Vec<&str>, Error> {
} }
} }
pub async fn route_propfind<A: CheckAuthentication, R: Resource, C: CalendarStore>( pub async fn route_propfind<A: CheckAuthentication, R: Resource, C: CalendarStore + ?Sized>(
path: Path<R::UriComponents>, path: Path<R::UriComponents>,
body: String, body: String,
req: HttpRequest, req: HttpRequest,