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
/// basic protocol for strs;
pub trait Str {
    /// appends char `c`.
    fn inc(self, c:char) -> Self;

    /// pops the last char.
    fn dec(self) -> Self;

    /// appends str `s`.
    fn plus(self, s:&str) -> Self;

    /// `clear`.
    fn zero(self) -> Self;

    /// `shrink_to_fit`.
    fn shrink(self) -> Self;
}

impl Str for String {
    fn inc(mut self, c:char) -> Self
    { self.push(c); self }

    fn dec(mut self) -> Self
    { self.pop(); self }

    fn plus(mut self, s:&str) -> Self
    { self.push_str(s); self}

    fn zero(mut self) -> Self
    { self.clear(); self }

    fn shrink(mut self) -> Self
    { self.shrink_to_fit(); self }
}