diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 61608bf2..67b855fd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -54,7 +54,7 @@ jobs: if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository strategy: matrix: - rust: [stable, nightly, "1.85"] # 1.85 is the MSRV + rust: [stable, nightly, "1.86"] # 1.85 is the MSRV os: [ubuntu-latest, macos-latest, windows-latest] name: Build & test diff --git a/Cargo.toml b/Cargo.toml index 1c3af16c..421cc2fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ resolver = "2" [workspace.package] edition = "2024" -rust-version = "1.85" +rust-version = "1.86" license = "MIT OR Apache-2.0" homepage = "https://cot.rs" repository = "https://github.com/cot-rs/cot" diff --git a/cot-macros/src/admin.rs b/cot-macros/src/admin.rs index 9c09271a..1e1763e0 100644 --- a/cot-macros/src/admin.rs +++ b/cot-macros/src/admin.rs @@ -97,10 +97,6 @@ impl AdminModelDeriveBuilder { quote! { #[#crate_ident::__private::async_trait] impl #crate_ident::admin::AdminModel for #name { - fn as_any(&self) -> &dyn ::core::any::Any { - self - } - async fn get_total_object_counts( request: &#crate_ident::request::Request, ) -> #crate_ident::Result { diff --git a/cot/src/admin.rs b/cot/src/admin.rs index 42f193a2..1c599644 100644 --- a/cot/src/admin.rs +++ b/cot/src/admin.rs @@ -528,10 +528,8 @@ impl AdminModelManager for DefaultAdminMo } async fn form_context_from_object(&self, object: Box) -> Box { - let object_casted = object - .as_any() - .downcast_ref::() - .expect("Invalid object type"); + let object_any: &dyn Any = &*object; + let object_casted = object_any.downcast_ref::().expect("Invalid object type"); T::form_context_from_self(object_casted).await } @@ -557,11 +555,6 @@ impl AdminModelManager for DefaultAdminMo note = "add #[derive(cot::admin::AdminModel)] to the struct to automatically derive the trait" )] pub trait AdminModel: Any + Send + 'static { - /// Returns the object as an `Any` trait object. - // TODO: consider removing this when Rust trait_upcasting is stabilized and we - // bump the MSRV (lands in Rust 1.86) - fn as_any(&self) -> &dyn Any; - /// Get the objects of this model. async fn get_objects(request: &Request, pagination: Pagination) -> cot::Result> where diff --git a/cot/src/openapi.rs b/cot/src/openapi.rs index f6cde8c0..b7cc99d5 100644 --- a/cot/src/openapi.rs +++ b/cot/src/openapi.rs @@ -447,11 +447,7 @@ where Inner(handler, PhantomData, PhantomData) } -pub(crate) trait BoxApiEndpointRequestHandler: BoxRequestHandler + AsApiRoute { - // TODO: consider removing this when Rust trait_upcasting is stabilized and we - // bump the MSRV (lands in Rust 1.86) - fn as_box_request_handler(&self) -> &(dyn BoxRequestHandler + Send + Sync); -} +pub(crate) trait BoxApiEndpointRequestHandler: BoxRequestHandler + AsApiRoute {} pub(crate) fn into_box_api_endpoint_request_handler( handler: H, @@ -486,13 +482,9 @@ where } } - impl BoxApiEndpointRequestHandler for Inner - where - H: RequestHandler + AsApiRoute + Send + Sync, + impl BoxApiEndpointRequestHandler for Inner where + H: RequestHandler + AsApiRoute + Send + Sync { - fn as_box_request_handler(&self) -> &(dyn BoxRequestHandler + Send + Sync) { - self - } } Inner(handler, PhantomData) diff --git a/cot/src/router.rs b/cot/src/router.rs index c6fd91be..163cb969 100644 --- a/cot/src/router.rs +++ b/cot/src/router.rs @@ -172,10 +172,9 @@ impl Router { #[cfg(feature = "openapi")] RouteInner::ApiHandler(handler) => { if matches_fully { + let handler: &(dyn BoxRequestHandler + Send + Sync) = &**handler; return Some(HandlerFound { - // TODO: consider removing this when Rust trait_upcasting is - // stabilized and we bump the MSRV (lands in Rust 1.86) - handler: handler.as_box_request_handler(), + handler, app_name: self.app_name.clone(), name: route.name.clone(), params: Self::matches_to_path_params(&matches, Vec::new()),