1# downcast   ![Latest Version] 2 3[Latest Version]: https://img.shields.io/crates/v/downcast.svg 4 5A trait (& utilities) for downcasting trait objects back to their original types. 6 7## [link to API documentation](https://docs.rs/downcast) 8 9## example usage 10 11Add to your Cargo.toml: 12 13```toml 14[dependencies] 15downcast = "0.12" 16``` 17 18Add to your crate root: 19 20```rust 21#[macro_use] 22extern crate downcast; 23``` 24 25* [simple](examples/simple.rs) showcases the most simple usage of this library. 26* [with_params](examples/with_params.rs) showcases how to deal with traits who have type parameters. 27* [sync_service](examples/sync_service.rs) showcases how to downcast `Arc`-pointers. 28 29## build features 30 31* **std (default)** enables all functionality requiring the standard library (`Downcast::downcast()`). 32* **nightly** enables all functionality requiring rust nightly (`Any::type_name()`). 33 34## faq 35 36__Q: I'm getting `the size for values of type XXX cannot be known at compile time` errors, what am i doing wrong?__ 37 38A: Make sure you use the corresponding `Any` bound along with the `Downcast` traits. So, `Any` for `Downcast` and `AnySync` for `DowncastSync`. 39 40__Q: Can i cast trait objects to trait objects?__ 41 42A: No, that is currently no possible in safe rust - and unsafe solutions are very tricky, as well. If you found a solution, feel free to share it! 43 44__Q: What is the difference between this and the `downcast-rs` crate on crates.io?__ 45 46A: At the moment, there isn't one, really. 47There was an unfortunate naming clash. You may consider using the other crate, as it is more actively maintained. 48This one is considered feature-complete and frozen in functionality. 49Hopefully, one day, the Rust language will make downcasting easier and we will need neither of these crates anymore! 50