From 5bf1e4b607683394179c651e1bd306167abc8c6f Mon Sep 17 00:00:00 2001 From: Dionisio Date: Fri, 13 Feb 2026 23:00:16 +0100 Subject: [PATCH] chore: migrate to Rust Edition 2024 - Update edition from 2021 to 2024 in Cargo.toml - Remove explicit `ref` bindings in pattern matches (di.rs, carddav_adapter.rs) Edition 2024 uses implicit ref binding modes - Refactor folder_handler.rs: change `impl IntoResponse` return types to concrete `axum::response::Response` to avoid lifetime capture issues (Edition 2024 captures all in-scope lifetimes in `impl Trait`) - All 101 tests pass, zero warnings --- Cargo.toml | 2 +- src/application/adapters/carddav_adapter.rs | 20 +++++----- src/common/di.rs | 2 +- src/interfaces/api/handlers/folder_handler.rs | 39 +++++++++---------- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 08a6f186..576d7c9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "oxicloud" version = "0.3.5" -edition = "2021" +edition = "2024" default-run = "oxicloud" diff --git a/src/application/adapters/carddav_adapter.rs b/src/application/adapters/carddav_adapter.rs index bf8502e9..87b1fb24 100644 --- a/src/application/adapters/carddav_adapter.rs +++ b/src/application/adapters/carddav_adapter.rs @@ -555,15 +555,15 @@ pub fn contact_to_vcard(contact: &ContactDto) -> String { vcard.push_str(&format!("UID:{}\r\n", contact.uid)); - if let (Some(ref last), Some(ref first)) = (&contact.last_name, &contact.first_name) { + if let (Some(last), Some(first)) = (&contact.last_name, &contact.first_name) { vcard.push_str(&format!("N:{};{};;;\r\n", last, first)); - } else if let Some(ref last) = &contact.last_name { + } else if let Some(last) = &contact.last_name { vcard.push_str(&format!("N:{};;;;\r\n", last)); - } else if let Some(ref first) = &contact.first_name { + } else if let Some(first) = &contact.first_name { vcard.push_str(&format!("N:;{};;;\r\n", first)); } - if let Some(ref fn_name) = contact.full_name { + if let Some(fn_name) = &contact.full_name { vcard.push_str(&format!("FN:{}\r\n", fn_name)); } else { // FN is mandatory in vCard 3.0 @@ -578,7 +578,7 @@ pub fn contact_to_vcard(contact: &ContactDto) -> String { } } - if let Some(ref nickname) = contact.nickname { + if let Some(nickname) = &contact.nickname { vcard.push_str(&format!("NICKNAME:{}\r\n", nickname)); } @@ -601,19 +601,19 @@ pub fn contact_to_vcard(contact: &ContactDto) -> String { vcard.push_str(&format!("ADR;TYPE={}:{}\r\n", addr.r#type.to_uppercase(), adr)); } - if let Some(ref org) = contact.organization { + if let Some(org) = &contact.organization { vcard.push_str(&format!("ORG:{}\r\n", org)); } - if let Some(ref title) = contact.title { + if let Some(title) = &contact.title { vcard.push_str(&format!("TITLE:{}\r\n", title)); } - if let Some(ref notes) = contact.notes { + if let Some(notes) = &contact.notes { vcard.push_str(&format!("NOTE:{}\r\n", notes.replace('\n', "\\n"))); } - if let Some(ref bday) = contact.birthday { + if let Some(bday) = &contact.birthday { vcard.push_str(&format!("BDAY:{}\r\n", bday.format("%Y-%m-%d"))); } - if let Some(ref photo) = contact.photo_url { + if let Some(photo) = &contact.photo_url { vcard.push_str(&format!("PHOTO;VALUE=URI:{}\r\n", photo)); } diff --git a/src/common/di.rs b/src/common/di.rs index 3c880e87..a72f56c9 100644 --- a/src/common/di.rs +++ b/src/common/di.rs @@ -590,7 +590,7 @@ impl AppServiceFactory { }; // 10b. Wire admin settings service when auth + DB are available - if let (Some(ref auth_svc), Some(ref pool)) = (&app_state.auth_service, &db_pool) { + if let (Some(auth_svc), Some(pool)) = (&app_state.auth_service, &db_pool) { let settings_repo = Arc::new( crate::infrastructure::repositories::pg::SettingsPgRepository::new(pool.clone()) ); diff --git a/src/interfaces/api/handlers/folder_handler.rs b/src/interfaces/api/handlers/folder_handler.rs index 2278b880..03a24570 100644 --- a/src/interfaces/api/handlers/folder_handler.rs +++ b/src/interfaces/api/handlers/folder_handler.rs @@ -63,16 +63,16 @@ impl FolderHandler { pub async fn list_root_folders( State(service): State, auth_user: AuthUser, - ) -> impl IntoResponse { - Self::list_folders_for_user(State(service), None, &auth_user).await + ) -> axum::response::Response { + Self::list_folders_for_user(service, None, &auth_user).await } /// Lists contents of a specific folder by its ID pub async fn list_folder_contents( State(service): State, Path(id): Path, - ) -> impl IntoResponse { - Self::list_folders(State(service), Some(&id)).await + ) -> axum::response::Response { + Self::list_folders_inner(service, Some(&id)).await } /// Lists root folders with pagination support @@ -80,10 +80,9 @@ impl FolderHandler { State(service): State, auth_user: AuthUser, _pagination: Query, - ) -> impl IntoResponse { + ) -> axum::response::Response { // For paginated root listing, filter by user as well - // Delegate to non-paginated user-filtered listing for now - Self::list_folders_for_user(State(service), None, &auth_user).await + Self::list_folders_for_user(service, None, &auth_user).await } /// Lists contents of a specific folder with pagination @@ -91,8 +90,8 @@ impl FolderHandler { State(service): State, Path(id): Path, pagination: Query, - ) -> impl IntoResponse { - Self::list_folders_paginated(State(service), pagination, Some(&id)).await + ) -> axum::response::Response { + Self::list_folders_paginated_inner(service, pagination, Some(&id)).await } /// Checks if a folder name matches the user home-folder convention. @@ -106,11 +105,11 @@ impl FolderHandler { folder_name == expected } - /// Lists folders, optionally filtered by parent ID - pub async fn list_folders( - State(service): State, + /// Lists folders, optionally filtered by parent ID (internal helper) + async fn list_folders_inner( + service: AppState, parent_id: Option<&str>, - ) -> impl IntoResponse { + ) -> axum::response::Response { match service.list_folders(parent_id).await { Ok(folders) => { (StatusCode::OK, Json(folders)).into_response() @@ -130,11 +129,11 @@ impl FolderHandler { /// Lists folders with user-based filtering for root listings. /// Non-admin users only see their own home folder at the root level. - pub async fn list_folders_for_user( - State(service): State, + async fn list_folders_for_user( + service: AppState, parent_id: Option<&str>, auth_user: &AuthUser, - ) -> impl IntoResponse { + ) -> axum::response::Response { match service.list_folders(parent_id).await { Ok(folders) => { // Only filter at root level (parent_id == None) @@ -168,12 +167,12 @@ impl FolderHandler { } } - /// Lists folders with pagination support - pub async fn list_folders_paginated( - State(service): State, + /// Lists folders with pagination support (internal helper) + async fn list_folders_paginated_inner( + service: AppState, Query(pagination): Query, parent_id: Option<&str>, - ) -> impl IntoResponse { + ) -> axum::response::Response { match service.list_folders_paginated(parent_id, &pagination).await { Ok(paginated_result) => { (StatusCode::OK, Json(paginated_result)).into_response()