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
use std::ops::Add;
use hangul::HangulExt;
pub enum Josa {
EunNeun,
IGa,
}
use Josa::{EunNeun, IGa};
impl Josa {
fn open(self) -> String {
match self {
EunNeun => "는",
IGa => "가",
}
.to_owned()
}
fn closed(self) -> String {
match self {
EunNeun => "은",
IGa => "이",
}
.to_owned()
}
}
impl Add<Josa> for &str {
type Output = String;
fn add(self, josa: Josa) -> String {
match self.chars().last().unwrap().is_open() {
Ok(true) => self.to_owned() + &josa.open(),
Ok(false) => self.to_owned() + &josa.closed(),
Err(_) => self.to_owned() + &josa.open(),
}
}
}