Last active
November 24, 2019 23:13
-
-
Save peterhuene/560550c63f0a6860f0e0b1fdf1c07f7c to your computer and use it in GitHub Desktop.
Durable Entity in Rust
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
use serde::{Deserialize, Serialize}; | |
#[derive(Serialize, Deserialize)] | |
struct Counter { | |
value: i32, | |
} | |
#[entity(type = "counter")] | |
impl Counter { | |
pub fn add(&mut self, amount: i32) { | |
self.value += amount; | |
} | |
#[operation(name = "clear")] | |
pub fn reset(&mut self) { | |
self.value = 0; | |
} | |
pub fn get(&self) -> i32 { | |
self.value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The default entity type will be the name of the implementing type (use the
type
argument to override).All public methods will be operations with a default name of the method name (use the
operation
attribute to override).