use wslink_rs::prelude::*;
#[derive(Default)]
struct SimpleServerProtocol {
click_count: u64,
}
impl SimpleServerProtocol {
#[wslink_rpc("demo.add")]
fn add(&self, a: f64, b: f64) -> f64 {
a + b
}
#[wslink_rpc("demo.click_count")]
fn click_count(&mut self) -> u64 {
self.click_count += 1;
self.click_count
}
#[wslink_rpc("demo.echo")]
fn echo(&self, value: serde_json::Value) -> serde_json::Value {
value
}
}
impl ServerProtocol for SimpleServerProtocol {
fn initialize(&mut self, _args: &ServerArgument, config: &mut ServerConfig) {
config
.register_rpc(Self::add())
.register_rpc(Self::click_count())
.register_rpc(Self::echo());
}
}
#[tokio::main]
async fn main() {
start::<SimpleServerProtocol>().await;
}