| Crates.io | rewrite-impl-trait |
| lib.rs | rewrite-impl-trait |
| version | 0.1.0 |
| created_at | 2023-01-14 19:02:01.664673+00 |
| updated_at | 2023-01-14 19:02:01.664673+00 |
| description | Rewrites impl Trait as method generics |
| homepage | https://github.com/austinjones/rewrite-impl-trait-rs |
| repository | https://github.com/austinjones/rewrite-impl-trait-rs |
| max_upload_size | |
| id | 758993 |
| size | 12,189 |
This crate converts usage of impl Trait in function signatures to method generics. Here are some examples:
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.
Run cargo add rewrite-impl-trait.
Then add #[rewrite_impl_trait::into_generic] to your trait, trait impl, or function.