mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
Add ?Sized to CalendarStore generics for dynamic dispatch
This commit is contained in:
@@ -6,14 +6,17 @@ use actix_web::{
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
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(
|
||||
"/{cid}/events",
|
||||
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>>,
|
||||
path: Path<String>,
|
||||
) -> impl Responder {
|
||||
|
||||
@@ -19,7 +19,7 @@ pub mod proptypes;
|
||||
pub mod resources;
|
||||
pub mod routes;
|
||||
|
||||
pub struct CalDavContext<C: CalendarStore> {
|
||||
pub struct CalDavContext<C: CalendarStore + ?Sized> {
|
||||
pub prefix: String,
|
||||
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());
|
||||
}
|
||||
|
||||
pub fn configure_dav<A: CheckAuthentication, C: CalendarStore>(
|
||||
pub fn configure_dav<A: CheckAuthentication, C: CalendarStore + ?Sized>(
|
||||
cfg: &mut web::ServiceConfig,
|
||||
prefix: String,
|
||||
auth: Arc<A>,
|
||||
|
||||
@@ -11,7 +11,7 @@ use tokio::sync::RwLock;
|
||||
use crate::proptypes::{write_href_prop, write_string_prop};
|
||||
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 calendar: Calendar,
|
||||
pub path: String,
|
||||
@@ -20,7 +20,7 @@ pub struct CalendarResource<C: CalendarStore> {
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl<C: CalendarStore> Resource for CalendarResource<C> {
|
||||
impl<C: CalendarStore + ?Sized> Resource for CalendarResource<C> {
|
||||
type MemberType = Self;
|
||||
type UriComponents = (String, String); // principal, calendar_id
|
||||
|
||||
|
||||
@@ -9,14 +9,14 @@ use rustical_store::event::Event;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub struct EventResource<C: CalendarStore> {
|
||||
pub struct EventResource<C: CalendarStore + ?Sized> {
|
||||
pub cal_store: Arc<RwLock<C>>,
|
||||
pub path: String,
|
||||
pub event: Event,
|
||||
}
|
||||
|
||||
#[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 MemberType = Self;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use tokio::sync::RwLock;
|
||||
|
||||
use super::calendar::CalendarResource;
|
||||
|
||||
pub struct PrincipalCalendarsResource<C: CalendarStore> {
|
||||
pub struct PrincipalCalendarsResource<C: CalendarStore + ?Sized> {
|
||||
prefix: String,
|
||||
principal: String,
|
||||
path: String,
|
||||
@@ -20,7 +20,7 @@ pub struct PrincipalCalendarsResource<C: CalendarStore> {
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl<C: CalendarStore> Resource for PrincipalCalendarsResource<C> {
|
||||
impl<C: CalendarStore + ?Sized> Resource for PrincipalCalendarsResource<C> {
|
||||
type UriComponents = ();
|
||||
type MemberType = CalendarResource<C>;
|
||||
|
||||
|
||||
@@ -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<'_, '_>,
|
||||
request: HttpRequest,
|
||||
events: Vec<Event>,
|
||||
@@ -76,7 +76,7 @@ async fn handle_report_calendar_query<C: CalendarStore>(
|
||||
.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>>,
|
||||
body: 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
|
||||
}
|
||||
|
||||
pub async fn handle_mkcol_calendar_set<C: CalendarStore>(
|
||||
pub async fn handle_mkcol_calendar_set<C: CalendarStore + ?Sized>(
|
||||
store: &RwLock<C>,
|
||||
prop_node: Node<'_, '_>,
|
||||
cid: String,
|
||||
@@ -139,7 +139,7 @@ pub async fn handle_mkcol_calendar_set<C: CalendarStore>(
|
||||
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)>,
|
||||
body: String,
|
||||
auth: AuthInfoExtractor<A>,
|
||||
|
||||
@@ -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>>,
|
||||
path: Path<(String, String, String)>,
|
||||
auth: AuthInfoExtractor<A>,
|
||||
@@ -39,7 +39,7 @@ pub async fn delete_event<A: CheckAuthentication, C: CalendarStore>(
|
||||
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>>,
|
||||
path: Path<(String, String, String)>,
|
||||
_auth: AuthInfoExtractor<A>,
|
||||
@@ -56,7 +56,7 @@ pub async fn get_event<A: CheckAuthentication, C: CalendarStore>(
|
||||
.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>>,
|
||||
path: Path<(String, String, String)>,
|
||||
body: String,
|
||||
|
||||
@@ -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>,
|
||||
body: String,
|
||||
req: HttpRequest,
|
||||
|
||||
Reference in New Issue
Block a user