-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlib.rs
53 lines (46 loc) · 1.54 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
extern crate boson;
use boson::types::{
dyn_module::DynamicModuleInternalError, dyn_module::DynamicModuleResult, object::Object,
};
use std::rc::Rc;
#[no_mangle]
pub fn open(_init_params: Rc<Object>) -> DynamicModuleResult {
println!("hello world (open)");
Ok(Rc::new(Object::Str(format!("called open()"))))
}
#[no_mangle]
pub fn close(_close_params: Rc<Object>) -> DynamicModuleResult {
println!("hello world (close)");
Ok(Rc::new(Object::Str(format!("called close()"))))
}
#[no_mangle]
pub fn write(_write_params: Rc<Object>) -> DynamicModuleResult {
println!("hello world (write)");
Ok(Rc::new(Object::Str(format!("called write()"))))
}
#[no_mangle]
pub fn read(_read_params: Rc<Object>) -> DynamicModuleResult {
println!("hello world (read)");
Ok(Rc::new(Object::Str(format!("called read()"))))
}
#[no_mangle]
pub fn exec(method: String, params: &Vec<Rc<Object>>) -> DynamicModuleResult {
match method.as_ref() {
"greet_me" => {
if params.len() != 1 {
return Err(DynamicModuleInternalError {
cause: format!("no_param"),
message: format!("parameter 'name' not found"),
});
}
let name = params[0].as_ref().describe();
return Ok(Rc::new(Object::Str(format!("Hello! {}", name))));
}
_ => {
return Err(DynamicModuleInternalError {
cause: format!("no_method"),
message: format!("method {} not found", method),
})
}
}
}