Skip to content

observer pattern restricted to ConcreteObserver struct instead of IObserver trait #9

@electricherd

Description

@electricherd

Hi,
I like your patterns very much btw., I needed the Observer Pattern (which doesn't consume like yours) and tried a little but needed one which can have not only have a ConcreteObserver but also AnotherConcreteObserver, which I think fits more to the purpose.
Since I didn't need detaching, I didn't have the identifying problem when detaching, and came up with a version which uses box and dyn, and no partialeq.
I am intermediate in Rust, I'd say, so I explain best with that.

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=5115d33f36e98f73611e1b979988d0f4

I even tried a little with detach, which I believe you have to kind of first find out if the dyn type matches (don't know how) and then use the partialeq trait on the concrete type like you did. Because I also had trouble with the trait itself, dyn, box, box dyn, &? in trait alone, I stopped here (I don't need detach), and I believe it could be interesting to you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions