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
use std::fmt::Display;
#[derive(Debug, Clone)]
pub struct JSONBoolean {
data: bool,
}
impl Display for JSONBoolean {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.to_string())
}
}
impl JSONBoolean {
/// Create a new empty JSON Boolean
pub fn new(data: bool) -> Self {
JSONBoolean { data }
}
/// Convert JSON Boolean to a Rust owned string
///
/// # Example
///
/// ```
/// use parson::JSONBoolean;
///
/// assert_eq!(JSONBoolean::new(true).to_string(), "true");
/// assert_eq!(JSONBoolean::new(false).to_string(), "false");
/// ```
pub fn to_string(&self) -> String {
self.data.to_string()
}
/// Get a Rust bool from the JSON Boolean
pub fn get_boolean(&self) -> bool {
self.data
}
}