- 2 Posts
- 4 Comments
VegOwOtenks@lemmy.worldto
Rust@programming.dev•[Help] Is there a way to detect all structs in the current crate that implement a certain trait?
1·1 year agoYou could wrap the entirety of your file in a monster macro but you’d still have to assign the macro result to a variable you need to register, which doesn’t sound viable to me at least.
Maybe you can use a script that would extract all the trait implementations and create the boilerplate glue code for you, something like this:
grep --recursive --only-matching "impl PluginFunction for \w*" functions/ | sed --quiet "s/functions\/\(.*\)\.rs:impl PluginFunction for \(\w*\)/crate::functions::\1::\2{}.register(\&mut functions_map)/p"I tried to recreate your situation locally but it may not match perfectly, maybe you’ll have to adjust it a little. When I run it on my file tree which looks like this
functions ├── attr.rs ├── export.rs └── render.rs 1 directory, 3 fileswhere every file has a content like this
// comment pub struct MyAttrStructName {} impl PluginFunction for MyAttrStructName { }Then I receive the following output:
crate::functions::attr::MyAttrStructName{}.register(&mut functions_map) crate::functions::export::MyExportStructName{}.register(&mut functions_map) crate::functions::render::MyRenderStructName{}.register(&mut functions_map)
You can, another comment mentioned that. Only, I didn’t mean to spread misinformation because I haven’t used anything else in years.
I was amazed to find out you can open a new tab by using middle-click in firefox.



Sorry, what does “clocking someone” mean? I tried to look it up but could only find explanations like: hit someone, especially in the face or alternatively measuring something with a clock/metronome.
From context: Is it related to fooling someone?