trurl@lemmy.sdf.orgtoretrocomputing@lemmy.sdf.org•What was the first modem you ever had? How fast was it?
11·
1 year agoIt was the U.S. Robotics 56k PCI Winmodem that Dell was selling with their “Dimension XPS” Pentium II desktops. I later bought a proper 56k PCI modem off of a high school classmate so that I could download Debian packages without having to reboot into Windows first.
Getting metadata like this requires adding an extension to the language, either directly in code (as with a macro) or by messing with the build process (running another pass through your code to extract the metadata).
If you’re not adverse to using a global, you could write a macro that you use instead of
impl
for these traits. So, for example:register_plugin!(impl MyTrait for MyStruct { /* regular impl stuff goes here */ });
This macro would populate the global with metadata about the association between MyStruct and MyTrait. You could then pass a copy of it to
AllFunctions::new
.Alternatively, write a macro that just does the registration, which is like what you’re already doing:
impl MyTrait for MyStruct { ... } register_plugin!(MyTrait, MyStruct);
Another option would be to write something funky in
build.rs
that does whateverrustdoc
does to discover impls and pass that to the rest of your code as const data. As a hack, you could have it invokerustdoc
and then parse the output.How dynamic is this plugin system, though? If you can only change the registered plugins by rebuilding, then automatic discovery doesn’t seem so warranted. Invoking a simple registration macro at the bottom of each file would save a lot of complexity budget.