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:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=14d32088c67b42ccc9346e50be28fba6

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