anixe / doku

fn(Code) -> Docs
MIT License
80 stars 5 forks source link

Generic types #3

Closed Patryk27 closed 2 years ago

Patryk27 commented 3 years ago

Our current derive macro doesn't understand generic types, e.g.:

struct Response<T> {
    body: T,
    pagination: Pagination,
}

... forcing users to implement the Document trait by hand:

impl<T: Document> Document for Response<T> {
    /* ... */
}

Adding support for generic types will boil down to making #[derive(Doku)] understand generics and adding automatic : Document bound for all of the type parameters (with an opt-out switch):

struct Wrapper<'a, B: Foo, C, const D: usize>
where
    B: Bar
{
    /* ... */
}

// should generate, more or less:

impl<'a, B: Foo, C, const D: usize> Wrapper<'a, B, C, D>
where
    B: Bar + Document
    C: Document
{
    /* ... */
}