use std::collections::hash_map::RandomState;
use std::collections::HashMap;
use serde_json::Value;
use new_home_application::app::ApplicationBuilder;
use new_home_application::communication::{MethodCall, MethodResult};
use new_home_application::method::{Method, MethodCallable, MethodError};
struct MyMethod {}
impl Method for MyMethod {
fn name(&self) -> String {
String::from("my_method")
}
fn description(&self) -> String {
Default::default()
}
fn help(&self) -> String {
Default::default()
}
fn set_arguments(&mut self, _: HashMap<String, Value, RandomState>) -> Result<(), MethodError> {
Ok(())
}
}
impl MethodCallable for MyMethod {
fn call(&mut self, _: MethodCall) -> MethodResult {
println!("Called MyMethod");
MethodResult {
code: 0,
message: Value::String(String::from("Hello")),
}
}
}
fn create_my_method() -> Box<dyn MethodCallable> {
Box::new(MyMethod {})
}
fn main() {
let mut app = ApplicationBuilder::new();
app.with(Box::new(create_my_method));
match app.run(String::from("127.0.0.1:1337")) {
Err(error) => {
println!("{}", error);
}
_ => {}
}
}