From 0849d364464dfe574d49218b30b0423b3bdf47ad Mon Sep 17 00:00:00 2001 From: Ashish Myles Date: Mon, 6 Jan 2025 21:21:17 -0500 Subject: [PATCH] Updated to 2021 edition, added `dyn` to all trait objects, and changed min version to 1.56. --- .github/workflows/main.yml | 2 +- Cargo.toml | 3 ++- src/lib.rs | 26 +++++++++++++------------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index afea7ea..f84b89f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - toolchain: [stable, 1.36] + toolchain: [stable, 1.56] steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 diff --git a/Cargo.toml b/Cargo.toml index 89d72cd..1737262 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "downcast-rs" -edition = "2015" +edition = "2021" version = "1.2.1" +rust-version = "1.56" repository = "https://github.com/marcianx/downcast-rs" description = """ Trait object downcasting support using only safe Rust. It supports type diff --git a/src/lib.rs b/src/lib.rs index 274351c..b3137c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,7 +97,7 @@ //! //! fn main() { //! // Create a trait object. -//! let mut base: Box = Box::new(Foo(42)); +//! let mut base: Box = Box::new(Foo(42)); //! //! // Try sequential downcasts. //! if let Some(foo) = base.downcast_ref::() { @@ -108,19 +108,19 @@ //! //! assert!(base.is::()); //! -//! // Fail to convert `Box` into `Box`. +//! // Fail to convert `Box` into `Box`. //! let res = base.downcast::(); //! assert!(res.is_err()); //! let base = res.unwrap_err(); -//! // Convert `Box` into `Box`. +//! // Convert `Box` into `Box`. //! assert_eq!(42, base.downcast::().map_err(|_| "Shouldn't happen.").unwrap().0); //! //! // Also works with `Rc`. -//! let mut rc: Rc = Rc::new(Foo(42)); +//! let mut rc: Rc = Rc::new(Foo(42)); //! assert_eq!(42, rc.downcast_rc::().map_err(|_| "Shouldn't happen.").unwrap().0); //! //! // Since this trait is `Sync`, it also supports `Arc` downcasts. -//! let mut arc: Arc = Arc::new(Foo(42)); +//! let mut arc: Arc = Arc::new(Foo(42)); //! assert_eq!(42, arc.downcast_arc::().map_err(|_| "Shouldn't happen.").unwrap().0); //! } //! ``` @@ -146,7 +146,7 @@ //! //! fn main() { //! // Create a trait object. -//! let mut base: Box> = Box::new(Bar(42.0)); +//! let mut base: Box> = Box::new(Bar(42.0)); //! //! // Try sequential downcasts. //! if let Some(foo) = base.downcast_ref::() { @@ -178,7 +178,7 @@ use __alloc::sync::Arc; /// Supports conversion to `Any`. Traits to be extended by `impl_downcast!` must extend `Downcast`. pub trait Downcast: Any { /// Convert `Box` (where `Trait: Downcast`) to `Box`. `Box` can - /// then be further `downcast` into `Box` where `ConcreteType` implements `Trait`. + /// then be further `downcast` into `Box` where `ConcreteType` implements `Trait`. fn into_any(self: Box) -> Box; /// Convert `Rc` (where `Trait: Downcast`) to `Rc`. `Rc` can then be /// further `downcast` into `Rc` where `ConcreteType` implements `Trait`. @@ -470,12 +470,12 @@ mod test { type $base_type, { $($sync_def)+ }, [{ - // Fail to convert Arc into Arc. + // Fail to convert Arc into Arc. let arc: $crate::__alloc::sync::Arc<$base_type> = $crate::__alloc::sync::Arc::new(Foo(42)); let res = arc.downcast_arc::(); assert!(res.is_err()); let arc = res.unwrap_err(); - // Convert Arc into Arc. + // Convert Arc into Arc. assert_eq!( 42, arc.downcast_arc::().map_err(|_| "Shouldn't happen.").unwrap().0); }]); @@ -546,20 +546,20 @@ mod test { assert!(base.is::()); - // Fail to convert Box into Box. + // Fail to convert Box into Box. let res = base.downcast::(); assert!(res.is_err()); let base = res.unwrap_err(); - // Convert Box into Box. + // Convert Box into Box. assert_eq!( 6*9, base.downcast::().map_err(|_| "Shouldn't happen.").unwrap().0); - // Fail to convert Rc into Rc. + // Fail to convert Rc into Rc. let rc: $crate::__alloc::rc::Rc<$base_type> = $crate::__alloc::rc::Rc::new(Foo(42)); let res = rc.downcast_rc::(); assert!(res.is_err()); let rc = res.unwrap_err(); - // Convert Rc into Rc. + // Convert Rc into Rc. assert_eq!( 42, rc.downcast_rc::().map_err(|_| "Shouldn't happen.").unwrap().0);