rewrite-impl-trait 0.1.0

Rewrites impl Trait as method generics
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 11.72 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 279.26 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • austinjones/rewrite-impl-trait-rs
    0 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • austinjones

rewrite-impl-trait

This crate converts usage of impl Trait in function signatures to method generics. Here are some examples:

How it works

The macro into_generic converts impl Trait definitions in

#[rewrite_impl_trait::into_generic]
fn to_string(arg: impl ToString) -> String {
    arg.to_string()
}

// expands to:
fn to_string<RewriteImplTrait0: ToString>(arg: RewriteImplTrait0) -> String {
    arg.to_string()
}
pub trait AppendString {
    fn append_string(&mut self, param: impl ToString);
}

// expands to:
pub trait AppendString {
    fn append_string<RewriteImplTrait0: ToString>(&mut self, param: RewriteImplTrait0);
}

This can be used to work around language issues with impl Trait, such as a lack of support in type aliases. It also enables mockall, for traits that use impl Trait in method arguments.

Usage

Run cargo add rewrite-impl-trait.

Then add #[rewrite_impl_trait::into_generic] to your trait, trait impl, or function.