{"id":16312457,"url":"https://github.com/kiranandcode/observable-rs","last_synced_at":"2025-04-22T11:53:27.263Z","repository":{"id":112326001,"uuid":"143520909","full_name":"kiranandcode/observable-rs","owner":"kiranandcode","description":"Idiomatic, Unstable, observables for Rust","archived":false,"fork":false,"pushed_at":"2018-08-04T10:54:57.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-16T14:25:07.161Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kiranandcode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-04T10:51:02.000Z","updated_at":"2019-10-14T10:53:21.000Z","dependencies_parsed_at":"2023-05-12T23:00:34.086Z","dependency_job_id":null,"html_url":"https://github.com/kiranandcode/observable-rs","commit_stats":null,"previous_names":["kiranandcode/observable-rs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiranandcode%2Fobservable-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiranandcode%2Fobservable-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiranandcode%2Fobservable-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiranandcode%2Fobservable-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kiranandcode","download_url":"https://codeload.github.com/kiranandcode/observable-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250237800,"owners_count":21397399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T21:48:08.853Z","updated_at":"2025-04-22T11:53:27.246Z","avatar_url":"https://github.com/kiranandcode.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# observable \n### WARNING - this is an unstable crate that may change at any time. Use at your own risk\nIdiomatic Observables for rust.\n\n\n```rust\n#[derive(Debug, Clone)]\npub enum Event ( Example1, Example2, Example3 };\n\npub struct Game {\n  ...\n  observable: ObservableMixin\u003cEvent\u003e\n  ...\n}\nimpl AsMut\u003cObservableMixin\u003cEvent\u003e\u003e for Game { fn as_mut(\u0026mut self) -\u003e \u0026mut\nObservableMixin\u003cEvent\u003e { \u0026self.observable }\n/// Game is now an observable struct\n```\n\nTo create an observer, we need a struct that implements `Observer\u003cEvent\u003e`\n```rust\nstruct GameListener { }\n\nimpl Observer\u003cEvent\u003e for GameListener {\n  pub fn notify(\u0026self, event: Event) {\n        println!(\"Got event: {:?}\", event);\n  }\n}\n```\nTo add an observer, we can need to provide a weak reference to an observable object:\n```rust\n    let mut game = Game::new();\n    /// we need the clone here to upcast to Rc\u003cTrait\u003e\n    let observer : Rc\u003cObserver\u003cEvent\u003e\u003e = Rc::new(GameListener{}).clone();\n    game.register(Rc::downgrade(\u0026observer));\n```\nOr, if using the 'views' feature, with my other crate 'dependent_view',\n```rust\n    let mut game = Game::new();\n    let mut observer : DependentRc\u003cGameListener\u003e = DependentRc::new(GameListener{});\n    game.as_mut().register_dependable(\u0026mut observer);\n    // notice here how we get to keep the level of specificity with regards to our observer\n    // rather than having to upcast our only reference\n```\n\nAnd finally, we can send events to our observers:\n```rust\n    game.notify_observers(Event::Example1);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiranandcode%2Fobservable-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkiranandcode%2Fobservable-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiranandcode%2Fobservable-rs/lists"}