{"id":18082839,"url":"https://github.com/ranfdev/ev-stream-gtk-rs","last_synced_at":"2025-08-12T18:08:11.920Z","repository":{"id":104101363,"uuid":"444146162","full_name":"ranfdev/ev-stream-gtk-rs","owner":"ranfdev","description":null,"archived":false,"fork":false,"pushed_at":"2022-01-08T10:31:32.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T23:13:23.619Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ranfdev.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}},"created_at":"2022-01-03T17:31:44.000Z","updated_at":"2022-01-08T10:31:35.000Z","dependencies_parsed_at":"2023-06-18T21:37:00.666Z","dependency_job_id":null,"html_url":"https://github.com/ranfdev/ev-stream-gtk-rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ranfdev/ev-stream-gtk-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranfdev%2Fev-stream-gtk-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranfdev%2Fev-stream-gtk-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranfdev%2Fev-stream-gtk-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranfdev%2Fev-stream-gtk-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ranfdev","download_url":"https://codeload.github.com/ranfdev/ev-stream-gtk-rs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranfdev%2Fev-stream-gtk-rs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270109377,"owners_count":24528789,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-10-31T14:06:11.578Z","updated_at":"2025-08-12T18:08:11.870Z","avatar_url":"https://github.com/ranfdev.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ev-stream-gtk-rs\nThis is a little macro to help you handle gtk-rs events in an async way, by treating them as streams.\n\nExample:\n```rust\nlet my_stream = ev_stream!(button, clicked, |target|);\n```\n\n### Advantages\n#### Streams can have inner state\nInstead of having mutable shared state, streams can have some inner state.\nSkipping shared state means less cloning =\u003e more performance and better ergonomics.\n\nLet's say I want to print the number of times a button gets clicked:\n```rust\nlet click_stream = ev_stream!(button, clicked, |target|);\nlet fut = click_stream\n  .zip(0..)\n  .for_each(|(_, n)| println!(\"Clicked {} times!\", n));\n```\n\nYou can also keep some data between one event and the next, using fold.\nI use this to keep a request in the background, until a new event comes.\nWhen the next event comes, the previous request gets dropped and cancelled (automatically).\n```rust\nlet search_changed = ev_stream!(search_text_box, search_changed, |target|);\nlet fut = search_changed\n  .fold(None::\u003cRemoteHandle\u003c()\u003e\u003e, |state, target| {\n    fetch_data(target.text())\n  });\n```\n\n#### Multiple streams can be combined:\n```rust\n// Basic:\nlet stream1 = /*...*/;\nlet stream2 = /*...*/;\nlet stream3 = /*...*/;\nlet big_stream = stream1.chain(stream2).chain(stream3);\n\n\n// Print \"Hi\" one time. Then print \"Hi\" again after every click.\nlet click_stream = /*as before*/;\nlet click_stream_tokenized = click_stream.map(|_| ())\nlet fut = future::once(async {()})\n  .chain(click_stream_tokenized)\n  .for_each(|_| println!(\"Hi\"));\n```\nThe last example in a real context may become: \"Load data once, then load next data when `bottom_reached` event is fired\" (I use this in my app).\n\n\n#### They do automatic cleanup\nThe callback gets disconnected from the target widget when the stream is dropped.\n\n#### They require a single async ctx.\nIt's true that streams must be awaited for them to work.\nBut you can await multiple streams in a single async ctx, without the need to create an async ctx for each\ncallback!\n\n```rust\nspawn!(async move {\n  join!(button_clicked, bottom_reached)\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Franfdev%2Fev-stream-gtk-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Franfdev%2Fev-stream-gtk-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Franfdev%2Fev-stream-gtk-rs/lists"}