dyn_shim 0.1.1

Generate dyn-compatible shim traits
Documentation

dyn_shim

crates.io docs.rs CI license

Generate a dyn-compatible shim trait and blanket impl from a source trait that is not dyn-compatible.

Some traits are not dyn-compatible, so you cannot hold a mixed set of implementors behind one Box<dyn Trait>. The #[dyn_shim(Name)] attribute reads the trait it is applied to, builds a second trait containing only the dyn-compatible subset, and forwards each call to the original. Every implementor of the source trait then works as a dyn shim.

Usage

Add the dependency:

[dependencies]
dyn_shim = "0.1"

Annotate the trait with #[dyn_shim(Name)], where Name is the shim trait to generate:

use dyn_shim::dyn_shim;

#[dyn_shim(DynSink)]
trait Sink {
    // ...
}

See the API documentation for details.

Testing

cargo test

The suite includes trybuild UI tests under tests/ui/ that assert the compile errors for rejected traits and methods.

License

Licensed under the MIT license. See LICENSE for details.