Can you assert with Option<Box<dyn Trait>>?

Hi, i'm trying to create container wrapper with the similar API to HashMap with trait objects inside. On insert and on remove id like to output Option and assert it similar to how its shown in this doc: but i get an compiler error that == not defined for Option<Box>. Not sure what to do, since Eq, PartialEq didnt solve my problem.

Here's a playground link to an example

You can

    assert!(container.pop_entity("e10").is_none());
    // or `.is_some()`

If you want actual equality operations for Option<T>, you'll need them for T. In this case, that's a Box<dyn Status>, and you would have to decide what it means for those to be equal or not.

I don't know that it's the best way, but here's one way.

2 Likes

Awesome, thanks a lot!