Skip to content

Commit 6dc14ac

Browse files
authored
refactor!: use trait_upcasting, bump MSRV to 1.86 (#412)
1 parent 5816fb9 commit 6dc14ac

File tree

6 files changed

+9
-29
lines changed

6 files changed

+9
-29
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository
5555
strategy:
5656
matrix:
57-
rust: [stable, nightly, "1.85"] # 1.85 is the MSRV
57+
rust: [stable, nightly, "1.86"] # 1.85 is the MSRV
5858
os: [ubuntu-latest, macos-latest, windows-latest]
5959

6060
name: Build & test

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ resolver = "2"
1919

2020
[workspace.package]
2121
edition = "2024"
22-
rust-version = "1.85"
22+
rust-version = "1.86"
2323
license = "MIT OR Apache-2.0"
2424
homepage = "https://cot.rs"
2525
repository = "https://github.com/cot-rs/cot"

cot-macros/src/admin.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ impl AdminModelDeriveBuilder {
9797
quote! {
9898
#[#crate_ident::__private::async_trait]
9999
impl #crate_ident::admin::AdminModel for #name {
100-
fn as_any(&self) -> &dyn ::core::any::Any {
101-
self
102-
}
103-
104100
async fn get_total_object_counts(
105101
request: &#crate_ident::request::Request,
106102
) -> #crate_ident::Result<u64> {

cot/src/admin.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,8 @@ impl<T: AdminModel + Send + Sync + 'static> AdminModelManager for DefaultAdminMo
528528
}
529529

530530
async fn form_context_from_object(&self, object: Box<dyn AdminModel>) -> Box<dyn FormContext> {
531-
let object_casted = object
532-
.as_any()
533-
.downcast_ref::<T>()
534-
.expect("Invalid object type");
531+
let object_any: &dyn Any = &*object;
532+
let object_casted = object_any.downcast_ref::<T>().expect("Invalid object type");
535533

536534
T::form_context_from_self(object_casted).await
537535
}
@@ -557,11 +555,6 @@ impl<T: AdminModel + Send + Sync + 'static> AdminModelManager for DefaultAdminMo
557555
note = "add #[derive(cot::admin::AdminModel)] to the struct to automatically derive the trait"
558556
)]
559557
pub trait AdminModel: Any + Send + 'static {
560-
/// Returns the object as an `Any` trait object.
561-
// TODO: consider removing this when Rust trait_upcasting is stabilized and we
562-
// bump the MSRV (lands in Rust 1.86)
563-
fn as_any(&self) -> &dyn Any;
564-
565558
/// Get the objects of this model.
566559
async fn get_objects(request: &Request, pagination: Pagination) -> cot::Result<Vec<Self>>
567560
where

cot/src/openapi.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,7 @@ where
447447
Inner(handler, PhantomData, PhantomData)
448448
}
449449

450-
pub(crate) trait BoxApiEndpointRequestHandler: BoxRequestHandler + AsApiRoute {
451-
// TODO: consider removing this when Rust trait_upcasting is stabilized and we
452-
// bump the MSRV (lands in Rust 1.86)
453-
fn as_box_request_handler(&self) -> &(dyn BoxRequestHandler + Send + Sync);
454-
}
450+
pub(crate) trait BoxApiEndpointRequestHandler: BoxRequestHandler + AsApiRoute {}
455451

456452
pub(crate) fn into_box_api_endpoint_request_handler<HandlerParams, H>(
457453
handler: H,
@@ -486,13 +482,9 @@ where
486482
}
487483
}
488484

489-
impl<HandlerParams, H> BoxApiEndpointRequestHandler for Inner<HandlerParams, H>
490-
where
491-
H: RequestHandler<HandlerParams> + AsApiRoute + Send + Sync,
485+
impl<HandlerParams, H> BoxApiEndpointRequestHandler for Inner<HandlerParams, H> where
486+
H: RequestHandler<HandlerParams> + AsApiRoute + Send + Sync
492487
{
493-
fn as_box_request_handler(&self) -> &(dyn BoxRequestHandler + Send + Sync) {
494-
self
495-
}
496488
}
497489

498490
Inner(handler, PhantomData)

cot/src/router.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,9 @@ impl Router {
172172
#[cfg(feature = "openapi")]
173173
RouteInner::ApiHandler(handler) => {
174174
if matches_fully {
175+
let handler: &(dyn BoxRequestHandler + Send + Sync) = &**handler;
175176
return Some(HandlerFound {
176-
// TODO: consider removing this when Rust trait_upcasting is
177-
// stabilized and we bump the MSRV (lands in Rust 1.86)
178-
handler: handler.as_box_request_handler(),
177+
handler,
179178
app_name: self.app_name.clone(),
180179
name: route.name.clone(),
181180
params: Self::matches_to_path_params(&matches, Vec::new()),

0 commit comments

Comments
 (0)