cyqsimon / documented Goto Github PK
View Code? Open in Web Editor NEWTraits and derive macros for accessing your type's documentation at runtime.
License: MIT License
Traits and derive macros for accessing your type's documentation at runtime.
License: MIT License
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.
In my case I could assign the type ()
as a default for L
:
pub enum Instr<L = ()> {
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?
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.