How to fix the warning about unused Boxed trait object

I've created some callback code based on the stackoverflow example. The code works, but I don't understand how to fix a warning I'm getting. I thought I might need to call drop() explicitly, but I can't make that work.

Here is the code:

Thanks,
-jgilray

Since the warning isn't valid - you don't actually want to call this function - you really just need to silence the warning. Both let _ = ... and an explicit drop will do this:

let _ = self.callbacks.remove(id);
// or (less commonly used):
drop(self.callbacks.remove(id));

let _ = ... is fairly common, and should be read as "I don't care about the result, and I explicitly telling the compiler that". I mostly see it when ignoring Results, but it should work for other #[must_use] types as well.

Thanks @daboross!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.