Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/storycraft/async-component
Zero overhead reactive programming in Rust
https://github.com/storycraft/async-component
Last synced: 2 months ago
JSON representation
Zero overhead reactive programming in Rust
- Host: GitHub
- URL: https://github.com/storycraft/async-component
- Owner: storycraft
- License: apache-2.0
- Created: 2022-11-12T05:44:35.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-02T16:31:53.000Z (almost 2 years ago)
- Last Synced: 2024-10-03T08:45:54.115Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 253 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Async component
Zero overhead reactive programming## Example
See `async_component/examples/example.rs` for simple example.See `examples/gui-demo` project for example using with gui(winit, raqote, pixels).
### Code
```Rust
use async_component::AsyncComponent;// AsyncComponent trait only has update method which is like future and context is available globally when accessing component.
// Due to this behavior intergrating with async functions are very easy without async trait support. See StreamCell below.
#[derive(Debug, AsyncComponent)]
struct CounterComponent {
// State must be wrapped with StateCell
#[state(Self::on_counter_update)]
counter: StateCell,// Stream
// Async stream is polled using global component context
#[state(Self::on_counter_recv)]
counter_recv: StreamCell>,
}impl CounterComponent {
fn on_counter_update(&mut self, _: ()) {
println!("Counter updated to: {}", *self.counter);
}fn on_counter_recv(&mut self, counter: i32) {
*self.sub_component.counter = counter;
}
}
```Running this component stream will print initial value first and print changed value if new values are sent through channel.
```
Counter updated to: 0
Counter updated to: ...
```