From ed3050915cfaee7a38a033f75761705fa9fc1569 Mon Sep 17 00:00:00 2001 From: Ashish Myles Date: Mon, 6 Jan 2025 23:16:56 -0500 Subject: [PATCH] Refine the trait and method documentation. --- src/lib.rs | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0a70640..ed8bc3e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,9 +29,8 @@ //! downcast-rs = { version = "2.0.1", default-features = false } //! ``` //! -//! To make a trait downcastable, make it extend either `downcast::Downcast` or -//! `downcast::DowncastSync` and invoke `impl_downcast!` on it as in the examples -//! below. +//! To make a trait downcastable, make it extend either `Downcast` or `DowncastSync` and invoke +//! `impl_downcast!` on it as in the examples below. //! //! Since 2.0.0, the minimum supported Rust version is 1.56. //! @@ -185,16 +184,16 @@ 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`. + /// Converts `Box` (where `Trait: Downcast`) to `Box`, which can then be + /// `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`. + /// Converts `Rc` (where `Trait: Downcast`) to `Rc`, which can then be further + /// `downcast` into `Rc` where `ConcreteType` implements `Trait`. fn into_any_rc(self: Rc) -> Rc; - /// Convert `&Trait` (where `Trait: Downcast`) to `&Any`. This is needed since Rust cannot + /// Converts `&Trait` (where `Trait: Downcast`) to `&Any`. This is needed since Rust cannot /// generate `&Any`'s vtable from `&Trait`'s. fn as_any(&self) -> &dyn Any; - /// Convert `&mut Trait` (where `Trait: Downcast`) to `&Any`. This is needed since Rust cannot + /// Converts `&mut Trait` (where `Trait: Downcast`) to `&Any`. This is needed since Rust cannot /// generate `&mut Any`'s vtable from `&mut Trait`'s. fn as_any_mut(&mut self) -> &mut dyn Any; } @@ -206,11 +205,10 @@ impl Downcast for T { fn as_any_mut(&mut self) -> &mut dyn Any { self } } -/// Extends `Downcast` to support `Send` traits that thus support `Box` downcasting as well. +/// Extends `Downcast` for `Send` traits to support upcasting to `Box` as well. pub trait DowncastSend: Downcast + Send { - /// Convert `Box` (where `Trait: DowncastSend`) to `Box`. - /// `Box` can then be further `downcast` into `Box` where - /// `ConcreteType` implements `Trait`. + /// Converts `Box` (where `Trait: DowncastSend`) to `Box`, which + /// can then be `downcast` into `Box` where `ConcreteType` implements `Trait`. fn into_any_send(self: Box) -> Box; } @@ -219,14 +217,15 @@ impl DowncastSend for T { } #[cfg(feature = "sync")] -/// Extends `DowncastSend` to support `Sync` traits that thus support `Arc` downcasting as well. +/// Extends `DowncastSend` for `Sync` traits to support upcasting to `Box` +/// and `Arc` downcasting. pub trait DowncastSync: DowncastSend + Sync { - /// Convert `Box` (where `Trait: DowncastSync`) to `Box`. - /// `Box` can then be further `downcast` into `Box` where - /// `ConcreteType` implements `Trait`. + /// Converts `Box` (where `Trait: DowncastSync`) to `Box`, + /// which can then be `downcast` into `Box` where `ConcreteType` implements + /// `Trait`. fn into_any_sync(self: Box) -> Box; - /// Convert `Arc` (where `Trait: DowncastSync`) to `Arc`. `Arc` can then be - /// further `downcast` into `Arc` where `ConcreteType` implements `Trait`. + /// Converts `Arc` (where `Trait: DowncastSync`) to `Arc`, which can then be + /// `downcast` into `Arc` where `ConcreteType` implements `Trait`. fn into_any_arc(self: Arc) -> Arc; } @@ -236,7 +235,7 @@ impl DowncastSync for T { fn into_any_arc(self: Arc) -> Arc { self } } -/// Adds downcasting support to traits that extend `downcast::Downcast` by defining forwarding +/// Adds downcasting support to traits that extend `Downcast` by defining forwarding /// methods to the corresponding implementations on `std::any::Any` in the standard library. /// /// See