What is a convenient way to check a Box<Any>
is ()
(created by Box::new(())
).
Currently I have this, but I suspect there might be a more compact way to express this since the assignment seems redundant.
pub fn some_function(value: Box<Any>) {
if let Some(&()) = value.downcast_ref() {
// pass
} else {
panic!();
}
}
This can be done using
Any::is
method, eg: