https://github.com/compeydev/signals-rs
A lua(u)-inspired implementation of signals/events in rust.
https://github.com/compeydev/signals-rs
lua lua-signals luau luau-signals rust rust-library signals signals-rs
Last synced: 6 months ago
JSON representation
A lua(u)-inspired implementation of signals/events in rust.
- Host: GitHub
- URL: https://github.com/compeydev/signals-rs
- Owner: CompeyDev
- Created: 2023-03-23T09:35:12.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-12T09:27:09.000Z (over 2 years ago)
- Last Synced: 2025-04-12T02:11:36.460Z (6 months ago)
- Topics: lua, lua-signals, luau, luau-signals, rust, rust-library, signals, signals-rs
- Language: Rust
- Homepage: http://docs.devcomp.xyz/signals_rs
- Size: 1.2 MB
- Stars: 14
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
A lua(u)-inspired implementation of signals/events in rust.
A signal is a global state switch which can be used as a gateway for conditional code execution. Signals can be activated by first "connecting" to them with a callback, then "firing" them to toggle their state.
```rs
let mut some_signal = Signal::new();let (connection, connection_id) = some_signal.connect(&|_| println!("This signal has been fired, continuing..."));
// We can now fire this connection to execute its registered callback.
// Do note that in a more complicated scenario with multiple connections
// to a signal, a connection_id parameter must be passed.
connection.fire(None, None);// This "disconnects" from a signal and removes the registered callback, as it is no longer required.
connection.disconnect(Some(connection_id));// Signals can be destroyed or dropped too.
some_signal.destroy();
```Signals are especially useful as lightweight events for global state sync-ups.
# Installation
In order to install signals-rs, first switch to a nightly channel (`rustup toolchain install nightly`) for your rust compiler and then you can add it as such to your dependencies section in `Cargo.toml`:```toml
[dependencies]
signals_rs = { git = "https://github.com/CompeyDev/signals-rs.git", rev = "8a650a1" }
```# Features
As of now, this crate consists 1 feature, namely `log`. This feature is opt-in and enables progress logging for various activities, classified into "errors", "warns", and "info" logs. Useful for debugging purposes.It can be enabled as such:
```toml
[dependencies]
signals_rs = { git = "https://github.com/CompeyDev/signals-rs.git", rev = "8a650a1", features = ["log"] }
```