{"id":24304283,"url":"https://github.com/yoep/fx-callback","last_synced_at":"2026-02-10T07:31:41.347Z","repository":{"id":272634914,"uuid":"917269789","full_name":"yoep/fx-callback","owner":"yoep","description":"A subscription based callback to inform subscribers about relevant data events within structs.","archived":false,"fork":false,"pushed_at":"2025-12-27T20:28:36.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-29T09:48:06.317Z","etag":null,"topics":["callback","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yoep.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2025-01-15T17:12:28.000Z","updated_at":"2025-12-27T20:42:42.000Z","dependencies_parsed_at":"2025-01-15T19:38:29.564Z","dependency_job_id":"fc586829-a73c-4ec0-9d6f-2fe5eae83133","html_url":"https://github.com/yoep/fx-callback","commit_stats":null,"previous_names":["yoep/fx-callback"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/yoep/fx-callback","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoep%2Ffx-callback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoep%2Ffx-callback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoep%2Ffx-callback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoep%2Ffx-callback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoep","download_url":"https://codeload.github.com/yoep/fx-callback/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoep%2Ffx-callback/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29293948,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T03:42:42.660Z","status":"ssl_error","status_checked_at":"2026-02-10T03:42:41.897Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["callback","rust"],"created_at":"2025-01-17T01:19:15.564Z","updated_at":"2026-02-10T07:31:41.332Z","avatar_url":"https://github.com/yoep.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FX-Callback\n![Build](https://github.com/yoep/fx-callback/workflows/Build/badge.svg)\n![Version](https://img.shields.io/github/v/tag/yoep/fx-callback?label=version)\n[![Crates](https://img.shields.io/crates/v/fx-callback)](https://crates.io/crates/fx-callback)\n[![License: Apache-2.0](https://img.shields.io/github/license/yoep/fx-callback)](./LICENSE)\n[![codecov](https://codecov.io/gh/yoep/fx-callback/branch/master/graph/badge.svg?token=A801IOOZAH)](https://codecov.io/gh/yoep/fx-callback)\n\nA subscription based callback for data events that might occur within one or more structs.\nIt is mainly used within the FX landscape to allow events to be published between multiple structs.\n\n## Example\n\n```rust\nuse fx_callback::{Callback, MultiThreadedCallback, Subscriber, Subscription};\n\n/// The events of the struct that informs subscribers about changes to the data within the struct.\n#[derive(Debug, Clone, PartialEq)]\nenum MyEvent {\n    Foo,\n}\n\n/// The struct to which an interested subscriber can subscribe to.\n#[derive(Debug)]\nstruct Example {\n    callbacks: MultiThreadedCallback\u003cMyEvent\u003e,\n}\n\nimpl Example {\n    fn invoke_event(\u0026self) {\n        self.callbacks.invoke(MyEvent::Foo);\n    }\n}\n\nimpl Callback\u003cMyEvent\u003e for Example {\n    fn subscribe(\u0026self) -\u003e Subscription\u003cMyEvent\u003e {\n        self.callbacks.subscribe()\n    }\n\n    fn subscribe_with(\u0026self, subscriber: Subscriber\u003cMyEvent\u003e) {\n        self.callbacks.subscribe_with(subscriber)\n    }\n}\n```\n\n## Usage\n\n### Subscription/event holder\n\nTo get started with adding callbacks to your structs, add one of the implementations of the `Callback` trait.\nMake sure that the struct implements the `Debug` trait.\n\n```rust\nuse fx_callback::{Callback, MultiThreadedCallback};\n\n#[derive(Debug)]\npub struct MyStruct {\n    callbacks: MultiThreadedCallback\u003cMyEvent\u003e,\n}\n```\n\nAdd the `Callback` trait implementation to your struct to allow adding callbacks.\n\n```rust\nimpl Callback\u003cMyEvent\u003e for MyStruct {\n    fn subscribe(\u0026self) -\u003e Subscription\u003cMyEvent\u003e {\n        self.callbacks.subscribe()\n    }\n    \n    fn subscribe_with(\u0026self, subscriber: Subscriber\u003cMyEvent\u003e) {\n        self.callbacks.subscribe_with(subscriber)\n    }\n}\n```\n\nWhen you want to inform subscribers about a certain event, call the `invoke` method.\n\n```rust\nimpl MyStruct {\n    pub fn invoke_event(\u0026self) {\n        self.callbacks.invoke(MyEvent::Foo);\n    }\n}\n```\n\n### Subscriber\n\nThe interested subscriber can subscribe to the interested event of a struct that implements the `Callback` trait.\n\n```rust\nuse fx_callback::{Callback, MultiThreadedCallback, Subscriber, Subscription};\nuse tokio::runtime::Runtime;\n\nfn main() {\n    let runtime = Runtime::new().unwrap();\n    let struct_with_callback = MyStruct::new();\n    \n    let mut receiver = struct_with_callback.subscribe();\n    runtime.spawn(async move {\n       loop {\n           if let Some(event) = receiver.recv().await {\n               println!(\"Received event: {}\", event);\n           } else {\n               break;\n           }\n       } \n    });\n\n    struct_with_callback.invoke_event();\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoep%2Ffx-callback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoep%2Ffx-callback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoep%2Ffx-callback/lists"}