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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
extern crate nature;
use nature::domain::*;
use nature::common::Result;
#[no_mangle]
#[allow(unused_attributes)]
#[allow(improper_ctypes_definitions)]
pub extern fn rtn_none(_para: &ConverterParameter) -> ConverterReturned {
ConverterReturned::None
}
#[no_mangle]
#[allow(unused_attributes)]
#[allow(improper_ctypes_definitions)]
pub extern fn rtn_logical_error(_para: &ConverterParameter) -> ConverterReturned {
ConverterReturned::LogicalError { msg: "logical".to_string() }
}
#[no_mangle]
#[allow(unused_attributes)]
#[allow(improper_ctypes_definitions)]
pub extern fn rtn_one(_para: &ConverterParameter) -> ConverterReturned {
let mut instance = Instance::default();
instance.data.content = "one".to_string();
ConverterReturned::Instances { ins: vec![instance] }
}
#[no_mangle]
#[allow(unused_attributes)]
#[allow(improper_ctypes_definitions)]
pub extern fn rtn_tow(_para: &ConverterParameter) -> ConverterReturned {
let mut one = Instance::default();
one.data.content = "one".to_string();
let mut two = Instance::default();
two.data.content = "two".to_string();
ConverterReturned::Instances { ins: vec![one, two] }
}
#[no_mangle]
#[allow(unused_attributes)]
#[allow(improper_ctypes_definitions)]
pub extern fn rtn_environment_error(_para: &ConverterParameter) -> ConverterReturned {
ConverterReturned::EnvError { msg: "aforethought".to_string() }
}
#[no_mangle]
#[allow(unused_attributes)]
#[allow(improper_ctypes_definitions)]
pub extern fn convert_before_test(para: &Instance) -> Result<Instance> {
let mut rtn = para.clone();
rtn.content = "hello".to_string();
Ok(rtn)
}
#[no_mangle]
#[allow(unused_attributes)]
#[allow(improper_ctypes_definitions)]
pub extern fn convert_after_test(para: &Vec<Instance>) -> Result<Vec<Instance>> {
let rtn = para.iter().map(|rtn| {
let mut rtn = rtn.clone();
rtn.content = "hello".to_string();
rtn
}).collect();
Ok(rtn)
}
#[no_mangle]
#[allow(unused_attributes)]
#[allow(improper_ctypes_definitions)]
pub extern fn append_star(ins: &Instance) -> Result<Instance> {
dbg!("----------- append_star ----------");
let mut ins = ins.clone();
ins.content = ins.content.to_string() + " *";
Ok(ins)
}
#[no_mangle]
#[allow(unused_attributes)]
#[allow(improper_ctypes_definitions)]
pub extern fn append_plus(ins: &Instance) -> Result<Instance> {
dbg!("----------- append_plus ----------");
let mut ins = ins.clone();
ins.content = ins.content.to_string() + " +";
Ok(ins)
}