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