{"id":19892887,"url":"https://github.com/cormacrelf/incremental-rs","last_synced_at":"2025-05-02T18:31:56.195Z","repository":{"id":161839762,"uuid":"559411879","full_name":"cormacrelf/incremental-rs","owner":"cormacrelf","description":"A Rust port of Jane Street's Incremental library.","archived":false,"fork":false,"pushed_at":"2025-01-08T01:18:13.000Z","size":525,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T04:52:32.008Z","etag":null,"topics":["incremental","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/incremental","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/cormacrelf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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-10-30T02:56:06.000Z","updated_at":"2025-03-29T05:43:46.000Z","dependencies_parsed_at":"2023-11-14T06:23:15.494Z","dependency_job_id":"e49a6390-f65c-4e8a-9b85-a283703d6474","html_url":"https://github.com/cormacrelf/incremental-rs","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cormacrelf%2Fincremental-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cormacrelf%2Fincremental-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cormacrelf%2Fincremental-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cormacrelf%2Fincremental-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cormacrelf","download_url":"https://codeload.github.com/cormacrelf/incremental-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252088634,"owners_count":21692830,"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":["incremental","rust"],"created_at":"2024-11-12T18:25:59.521Z","updated_at":"2025-05-02T18:31:51.184Z","avatar_url":"https://github.com/cormacrelf.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# incremental-rs\n\nA port of Jane Street's [Incremental][jane] library.\n\n- Pretty rigorous implementation of the basic Incr features, moderately well \n  tested and benchmarked, performs very similarly to the original.\n- Partial implementation of incremental-map\n\n[jane]: https://github.com/janestreet/incremental\n\n### Install\n\n```sh\ncargo add incremental\n```\n\n### Examples\n\nBasic usage:\n\n```rust\nuse incremental::IncrState;\n\nlet state = IncrState::new();\nlet variable = state.var(5);\nlet times_10 = variable.map(|num| num * 10);\nlet observer = times_10.observe();\n\n// stabilise will propagate any changes\nstate.stabilise();\nlet value = observer.value();\nassert_eq!(value, 50);\n\n// now mutate\nvariable.set(10);\nstate.stabilise();\n\n// watch as var was propagated through the tree, and reached our observer\nassert_eq!(observer.value(), 100);\n```\n\nSubscriptions, and an illustration of how propagation stops when nodes produce\nthe same value as last time:\n\n```rust\nuse incremental::{IncrState, Update};\n\n// A little system to compute the absolute value of an input\n// Note that the input could change (e.g. 5 to -5), but the\n// output may stay the same (5 both times).\nlet state = IncrState::new();\nlet variable = state.var(5i32);\nlet absolute = variable.map(|num| num.abs());\nlet observer = absolute.observe();\n\n// set up a subscription.\nuse std::{cell::RefCell, rc::Rc};\nlet latest = Rc::new(RefCell::new(None));\nlet latest_clone = latest.clone();\nlet subscription_token = observer.subscribe(move |update| {\n     *latest_clone.borrow_mut() = Some(update.cloned());\n});\n\n// initial stabilisation\nstate.stabilise();\nassert_eq!(observer.value(), 5);\nassert_eq!(latest.borrow().clone(), Some(Update::Initialised(5)));\n\n// now mutate, but such that the output of abs() won't change\nvariable.set(-5);\nstate.stabilise();\n// The subscription function was not called, because the `absolute` node\n// produced the same value as last time we stabilised.\nassert_eq!(latest.borrow().clone(), Some(Update::Initialised(5)));\nassert_eq!(observer.value(), 5);\n\n// now mutate such that the output changes too\nvariable.set(-10);\nstate.stabilise();\n// The observer did get a new value, and did call the subscription function\nassert_eq!(latest.borrow().clone(), Some(Update::Changed(10)));\nassert_eq!(observer.value(), 10);\n\n// now unsubscribe. this also implicitly happens if you drop the observer,\n// but you can individually unsubscribe particular subscriptions if you wish.\nobserver.unsubscribe(subscription_token);\n// dropping the observer also unloads any part of the computation graph\n// that was only running for the purposes of this particular observer\ndrop(observer);\n\n// now that the observer is dead, we can mutate the variable and nothing will\n// happen, like, at all. The absolute value will not be computed.\nvariable.set(100000000);\nlet recomputed = state.stats().recomputed;\nstate.stabilise();\nassert_eq!(recomputed, state.stats().recomputed);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcormacrelf%2Fincremental-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcormacrelf%2Fincremental-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcormacrelf%2Fincremental-rs/lists"}