Considering code like the following:
pub struct Generic<T> {
inner: Vec<T>, // just an example
}
impl<T> Generic<T> {
/// description for rustdoc
pub fn do_stuff(&self) {}
}
pub type Foo = Generic<bool>;
pub type Bar = Generic<usize>;
Is there a crate that would allow to turn the above into something like:
pub struct Foo {
inner: Vec<bool>, // just an example
}
impl Foo {
/// description for rustdoc
pub fn do_stuf(&self) {}
}
pub struct Bar {
inner: Vec<usize>, // just an example
}
impl Bar {
/// description for rustdoc
pub fn do_stuf(&self) {}
}
etc.
The idea being that the documentation for the latter would be easier to digest.
From the crates I do know, the closest would be inherent
, with something like:
use inherent::inherent;
trait Trait<T> {
fn do_stuff(&self) { }
}
pub struct Foo {
inner: Vec<bool>, // just an example
}
#[inherent]
impl Trait<bool> for Foo {
/// description for rustdoc
pub fn do_stuff(&self);
}
pub struct Bar {
inner: Vec<usize>, // just an example
}
#[inherent]
impl Trait<usize> for Bar {
/// description for rustdoc
pub fn do_stuff(&self);
}
which would allow to avoid the code duplication (the actual implementation would be in the trait), but documentation would be largely repeated (although for e.g. examples, that's necessary).