-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a5250c
commit 29134f8
Showing
1 changed file
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,60 @@ | ||
# rearch-rs | ||
|
||
Coming soon! | ||
The README is a large WIP, but below are some basics: | ||
|
||
## Getting Started | ||
First, you need to define some "capsules." | ||
There are several ways to define capsules, depending on your toolchain and opinions toward macros. | ||
|
||
### Macros (Optional), Stable and Nightly Rust | ||
Note: This particular example uses the nightly-only `better-api` feature. | ||
You can also write macros using the stable Rust syntax further below. | ||
```rust | ||
#[capsule] | ||
fn count(register: SideEffectRegistrar) -> (u8, impl Fn(u8) + Clone + Send + Sync) { | ||
let (state, set_state) = register(side_effects::state(0)); | ||
(*state, set_state) | ||
} | ||
|
||
#[capsule] | ||
fn count_plus_one() -> u8 { | ||
$count + 1 | ||
} | ||
|
||
let container = Container::new(); | ||
let ((count, set_count), count_plus_one) = container.read((count, count_plus_one)); | ||
``` | ||
|
||
### Vanilla, Nightly Rust (`better-api` feature) | ||
```rust | ||
fn count( | ||
_: CapsuleReader, register: SideEffectRegistrar, | ||
) -> (u8, impl Fn(u8) + Clone + Send + Sync) { | ||
let (state, set_state) = register(side_effects::state(0)); | ||
(*state, set_state) | ||
} | ||
|
||
fn count_plus_one(mut get: CapsuleReader, _: SideEffectRegistrar) -> u8 { | ||
get(count) + 1 | ||
} | ||
|
||
let container = Container::new(); | ||
let ((count, set_count), count_plus_one) = container.read((count, count_plus_one)); | ||
``` | ||
|
||
### Vanilla, Stable Rust | ||
```rust | ||
fn count( | ||
_: CapsuleReader, registrar: SideEffectRegistrar, | ||
) -> (u8, impl Fn(u8) + Clone + Send + Sync) { | ||
let (state, set_state) = registrar.register(side_effects::state(0)); | ||
(*state, set_state) | ||
} | ||
|
||
fn count_plus_one(mut reader: CapsuleReader, _: SideEffectRegistrar) -> u8 { | ||
reader.read(count) + 1 | ||
} | ||
|
||
let container = Container::new(); | ||
let ((count, set_count), count_plus_one) = container.read((count, count_plus_one)); | ||
``` |