Introducing `transient` - a reimplementation of `std::any::Any` with support for non-'static types
Hey everyone! I'm excited to have just release my first crate, transient. This crate provides an alternate implementation of the the std::any::Any dynamic typing mechanism that includes the support for non-'statictypes that is missing from the stdlib's version.
repo - https://github.com/JRRudy1/transient
docs - https://docs.rs/transient/0.1.1/transient
To use this crate you implement the simple Transient trait for a type (derive macro included) which captures its transient behavior (i.e. lifetimes and variance), after which you can cast to the reimplemented dyn Any trait object and later downcast to the original concrete type. Implementing this trait is unsafe but straight-forward, and once implemented everything else is safely enforced using the type system.
Notable features:
- Fully replicates the
std::anymodule - Near-identical API for
'statictypes with small changes for transient types - Supports any number of generic type/lifetime/const parameters
- No external dependencies without feature-gates
- Includes a (feature-gated) derive macro for the
Transienttrait - Provides
Transientimpls for many stdlib types - Provides (feature-gated)
Transientimpls for some foreign types - feel free to request more! - Extensive documentation including numerous examples
- Permissive MIT/APACHE-2.0 dual license
I decided to make this crate after running into the 'static-only limitation of the stdlib version on multiple occasions, such as when I wanted to erase the type of an ndarray::ArrayView<'v, T, D> to pass it through generic-forbidding code and ended up having to clone the data instead. If you have ever faced a situation like this (which I'll admit is fairly niche), then this is the crate for you!
Let me know what you think! Suggestions for improvement, constructive criticism, and feature requests are very welcome