1 unstable release

0.1.0 Jan 14, 2023

#65 in #rewrite

Download history 26/week @ 2024-07-22 4/week @ 2024-07-29 10/week @ 2024-08-05 7/week @ 2024-08-12 18/week @ 2024-08-19 2/week @ 2024-08-26 4/week @ 2024-09-02 8/week @ 2024-09-09 25/week @ 2024-09-16 21/week @ 2024-09-23 21/week @ 2024-09-30 31/week @ 2024-10-07 20/week @ 2024-10-14 15/week @ 2024-10-21 3/week @ 2024-10-28 18/week @ 2024-11-04

57 downloads per month

MIT license

6KB
82 lines

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.

Dependencies

~1.5MB
~37K SLoC