Closed TornaxO7 closed 1 year ago
"impl doesn't use only types from inside the current crate" — the type in collect!
needs to be defined in your crate. std::ops::Fn
is not defined in your crate.
You could do it like this:
pub struct CommandFromNormalized(fn(NormalizedCommand) -> Option<Box<dyn Command>>);
impl CommandFromNormalized {
const fn new<T: Command + 'static>() -> Self {
CommandFromNormalized(|general: NormalizedCommand| {
T::from_normalized(general).map(|cmd| cmd as Box<dyn Command>)
})
}
}
inventory::collect!(CommandFromNormalized);
…
inventory::submit!(CommandFromNormalized::new::<MyCommand>());
…
for command in inventory::iter::<CommandFromNormalized> {
if let Some(matching_command) = (command.0)(general) {
yay, it's working (the compiler doesn't complain anymore)! Thank you! happy pikadsu noises
Hi! I'd happy if you have some tips for me, because I'm a bit stuck at the moment.
Context
I have different commands whith have some common functions, one of them is a function to "parse" a string (in this case) and return themself if they match. I'm trying to collect those functions with your crate to be able to iterate through the functions
Code
Now here comes the relevant code:
Output
I'm getting the following error message:
Question
Do you have an idea how I can fix this?