1 use super::Value;
2 
3 pub trait Modifications {
append(&mut self, val: Self) -> bool4     fn append(&mut self, val: Self) -> bool;
prepend(&mut self, val: Self) -> bool5     fn prepend(&mut self, val: Self) -> bool;
6 }
7 
8 impl<T> Modifications for Value<T> {
append(&mut self, val: Self) -> bool9     fn append(&mut self, val: Self) -> bool {
10         match self {
11             Value::Array(ref mut lhs) => match val {
12                 Value::Array(rhs) => {
13                     lhs.extend(rhs);
14                     true
15                 }
16                 Value::Str(_) => {
17                     lhs.push(val);
18                     true
19                 }
20                 _ => false,
21             },
22             Value::Str(ref mut lhs) => match val {
23                 Value::Str(rhs) => {
24                     lhs.push_str(rhs.as_str());
25                     true
26                 }
27                 _ => false,
28             },
29             _ => false,
30         }
31     }
32 
prepend(&mut self, val: Self) -> bool33     fn prepend(&mut self, val: Self) -> bool {
34         match self {
35             Value::Array(ref mut lhs) => match val {
36                 Value::Array(rhs) => {
37                     lhs.splice(..0, rhs);
38                     true
39                 }
40                 Value::Str(_) => {
41                     lhs.insert(0, val);
42                     true
43                 }
44                 _ => false,
45             },
46             Value::Str(ref mut lhs) => match val {
47                 Value::Str(rhs) => {
48                     *lhs = format!("{}{}", rhs, lhs).into();
49                     true
50                 }
51                 _ => false,
52             },
53             _ => false,
54         }
55     }
56 }
57