Git Product home page Git Product logo

documented's People

Contributors

cyqsimon avatar imurx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

imurx

documented's Issues

Support Enums with Generic Type Parameters

I love the idea for this crate! Unfortunately when I tried to use it I ran into some trouble because the enum I wanted to apply DocumentedVariants to has a generic type parameter L:

#[derive(.., Clone, .., documented::DocumentedVariants)]
pub enum Instr<L> {
    /// Dispatch on the type of the value pointed to by `X1`.
    SwitchOnTerm { .. }
    // ..
}

The error I get says:

error[E0107]: missing generics for enum `Instr`
  --> src\bc\instr.rs:93:10
   |
93 | pub enum Instr<L> {
   |          ^^^^^ expected 1 generic argument
   |
note: enum defined here, with 1 generic parameter: `L`
  --> src\bc\instr.rs:93:10
   |
93 | pub enum Instr<L> {
   |          ^^^^^ -
help: add missing generic argument
   |
93 | pub enum Instr<L><L> {
   |               +++

I figured out a workaround though.

  1. In my case I could assign the type () as a default for L:

    pub enum Instr<L = ()> {
  2. Then I wrote a helper impl:

    impl<L: Clone> Instr<L> {
        pub fn doc_comment(&self) -> Option<&'static str> {
            let mapped: Instr<()> = self.clone().map_lbl(|_| ()); // Throw away `L`, make it `()`.
            documented::DocumentedVariants::get_variant_docs(&mapped).ok()
        }
    }

    Unfortunately this requires that L be Clone (still ok for my use case, but unsatisfying).

    Here map_lbl maps the L parameter to a new type. It's signature looks like this:

    impl<L> Instr<L> {
        pub fn map_lbl<M>(self, f: impl Fn(L) -> M) -> Instr<M> { .. }
    }

I'm not sure how the derive macro works, but it seems like handling generic type parameters just hasn't been implemented yet. Would this be easy to fix?

Add field comments

Hello, I want to use this to have comments on a toml with serde, and I like suffering.

Would you like for me to PR here if I end up making it happen?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.