@@ -46,7 +46,7 @@ fn main() {
4646
4747Target traits must be explicitly designated beforehand. There are three ways of doing it:
4848
49- ## ` #[cast_to] ` to ` impl ` item
49+ ### ` #[cast_to] ` to ` impl ` item
5050The trait implemented is designated as a target trait.
5151
5252``` rust
@@ -63,7 +63,7 @@ impl Greet for Data {
6363}
6464```
6565
66- ## ` #[cast_to(Trait)] ` to type definition
66+ ### ` #[cast_to(Trait)] ` to type definition
6767For the type, the traits specified as arguments to the ` #[cast_to(...)] ` attribute are designated as target traits.
6868
6969``` rust
@@ -82,7 +82,7 @@ impl Greet for Data {
8282struct Data ;
8383```
8484
85- ## ` castable_to!(Type => Trait1, Trait2) `
85+ ### ` castable_to!(Type => Trait1, Trait2) `
8686For the type, the traits following ` : ` are designated as target traits.
8787
8888``` rust
@@ -103,14 +103,22 @@ castable_to!(Data => Greet, std::fmt::Debug);
103103fn main () {}
104104```
105105
106+ ## ` Arc ` Support
107+ ` std::sync::Arc ` is unique in that it implement ` downcast ` method only on `dyn Any + Send + Sync + 'static'.
108+ To use with ` Arc ` , the following steps should be taken:
109+
110+ * Mark source traits with [ ` CastFromSync ` ] instead of [ ` CastFrom ` ]
111+ * Add ` [sync] ` flag to ` #[cast_to] ` and ` castable_to! ` as follows:
112+ ``` ignore
113+ #[cast_to([sync])]
114+ #[cast_to([sync] Trait1, Trait2)]
115+ castable_to!(Type => [sync] Trait, Trait2);
116+ ```
117+
106118# How it works
107119First of all, [ ` CastFrom ` ] trait makes it possible to retrieve an object of [ ` std::any::Any ` ]
108120from an object for a sub-trait of [ ` CastFrom ` ] .
109121
110- > [ ` CastFrom ` ] will become obsolete and be replaced with [ ` std::any::Any ` ]
111- > once [ unsized coercion] ( https://doc.rust-lang.org/reference/type-coercions.html#unsized-coercions )
112- > from a trait object to another trait object for its super-trait is implemented in the stable Rust.
113-
114122And the macros provided by ` intertrait ` generates trampoline functions for downcasting a trait object
115123for [ ` std::any::Any ` ] back to its concrete type and then creating a trait object for the target trait from it.
116124
@@ -143,4 +151,5 @@ dual licensed as above, without any additional terms or conditions.
143151
144152[ `std::any::Any` ] : https://doc.rust-lang.org/std/any/trait.Any.html
145153[ `TypeId` ] : https://doc.rust-lang.org/std/any/struct.TypeId.html
146- [ `CastFrom` ] : https://docs.rs/intertrait/*/intertrait/trait.CastFrom.html
154+ [ `CastFrom` ] : https://docs.rs/intertrait/*/intertrait/trait.CastFrom.html
155+ [ `CastFromSync` ] : https://docs.rs/intertrait/*/intertrait/trait.CastFromSync.html
0 commit comments