Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
electricherd opened this issue Jul 10, 2020 · 1 comment

Comments

@electricherd
Copy link

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.

@electricherd
Copy link
Author

actually it is restricted to the first registered observer's struct type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant