Skip to content

Instantly share code, notes, and snippets.

@peterhuene
Last active November 24, 2019 23:13
Show Gist options
  • Save peterhuene/560550c63f0a6860f0e0b1fdf1c07f7c to your computer and use it in GitHub Desktop.
Save peterhuene/560550c63f0a6860f0e0b1fdf1c07f7c to your computer and use it in GitHub Desktop.
Durable Entity in Rust
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
}
}
@peterhuene
Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment