forked from second-state/rust-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
40 lines (35 loc) · 1004 Bytes
/
main.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
#[derive(PartialEq)]
enum Lang {
English,
Spanish,
Chinese,
Texan,
}
struct Greeting {
message: String,
lang: Lang,
}
fn main() -> Result<(), String> {
println!("{}", greet(Lang::English)?);
println!("{}", greet(Lang::Texan)?);
println!("{}", greet(Lang::Spanish)?);
println!("{}", greet(Lang::Chinese)?);
Ok(())
}
fn greet (lang : Lang) -> Result<String, String> {
let mut v :Vec<Greeting> = Vec::new();
let g : Greeting = Greeting { lang: Lang::English, message: String::from("Hello WasmEdge!") };
v.push(g);
let g : Greeting = Greeting { lang: Lang::Spanish, message: String::from("Hola WasmEdge!") };
v.push(g);
let g : Greeting = Greeting { lang: Lang::Texan, message: String::from("Howdy WasmEdge!") };
v.push(g);
let g : Greeting = Greeting { lang: Lang::Chinese, message: String::from("WasmEdge 你好!") };
v.push(g);
for e in v {
if lang == e.lang {
return Ok(e.message);
}
}
return Err("Language not found!".to_string());
}