A set of helper macros
#[autoimpl]
is a variant of #[derive]
, supporting:
```rust use impl_tools::autoimpl; use std::fmt::Debug;
// Generates: impl<'a, T: Animal + ?Sized> Animal for Box
// Generates: impl
// Generates: impl
fn main() { struct Fish; impl Animal for Fish { fn numberoflegs(&self) -> u32 { 0 } }
let my_fish = Named {
name: "Nemo",
animal: Box::new(Fish),
};
assert_eq!(
format!("{my_fish:?} has {} legs!", my_fish.number_of_legs()),
r#"Named { name: "Nemo", .. } has 0 legs!"#
);
} ```
#[impl_default]
implements std::default::Default
:
```rust use impltools::{impldefault, impl_scope};
enum Tree { Ash, Beech, Birch, Willow }
implscope! { #[impldefault] struct Copse { tree_type: Tree, number: u32 = 7, } } ```
impl_scope!
is a function-like macro used to define a type plus its
implementations. It supports impl Self
syntax:
```rust use impltools::implscope; use std::fmt::Display;
impl_scope! {
/// I don't know why this exists
pub struct NamedThing
// Repeats generic parameters of type
impl Self {
fn format_name(&self) -> String {
format!("{}", self.name)
}
}
// Merges generic parameters of type
impl<O> Self where F: Fn(&str) -> O {
fn invoke(&self) -> O {
(self.func)(&self.format_name())
}
}
} ```
The MSRV is 1.56.0 (first to support Edition 2021).
Using a nightly compiler will improve diagnostics.
The COPYRIGHT file includes a list of contributors who claim copyright on this project. This list may be incomplete; new contributors may optionally add themselves to this list.
The impl-tools library is published under the terms of the Apache License, Version 2.0. You may obtain a copy of this licence from the LICENSE file or on the following webpage: https://www.apache.org/licenses/LICENSE-2.0