Trait nop_json::DebugToJson [−][src]
Trait that can be automatically derived for structs and enums. When it’s derived, a Debug implementation is also added,
so the object can be printed with println!
.
Example:
use nop_json::DebugToJson; #[derive(DebugToJson)] struct Point {x: i32, y: i32} let point = Point {x: 1, y: 2}; println!("{:?}", point);
Here is what automatic implementation expands to. If you write:
use nop_json::DebugToJson; #[derive(DebugToJson)] struct Point {x: i32, y: i32}
The implementation will be:
use nop_json::DebugToJson; struct Point {x: i32, y: i32} impl DebugToJson for Point { fn fmt(&self, out: &mut std::fmt::Formatter) -> std::fmt::Result { write!(out, "{{\"x\":")?; DebugToJson::fmt(&self.x, out)?; write!(out, ",\"y\":")?; DebugToJson::fmt(&self.y, out)?; write!(out, "}}") } } impl std::fmt::Debug for Point { fn fmt(&self, out: &mut std::fmt::Formatter) -> std::fmt::Result { DebugToJson::fmt(self, out) } }
For more information, see main page.
Required methods
Loading content...Provided methods
fn to_json_string(&self) -> String where
Self: Sized,
[src]
Self: Sized,
Any type that implements DebugToJson
can be converted to JSON string. For example DebugToJson
is implemented for primitive types:
use nop_json::DebugToJson; let smth = true; assert_eq!(smth.to_json_string(), "true".to_string());
For custom types:
use nop_json::DebugToJson; #[derive(DebugToJson)] struct Something {value: i32} let smth = Something {value: 123}; assert_eq!(smth.to_json_string(), "{\"value\":123}".to_string());
Implementations on Foreign Types
impl DebugToJson for ()
[src]
impl DebugToJson for isize
[src]
impl DebugToJson for i128
[src]
impl DebugToJson for i64
[src]
impl DebugToJson for i32
[src]
impl DebugToJson for i16
[src]
impl DebugToJson for i8
[src]
impl DebugToJson for usize
[src]
impl DebugToJson for u128
[src]
impl DebugToJson for u64
[src]
impl DebugToJson for u32
[src]
impl DebugToJson for u16
[src]
impl DebugToJson for u8
[src]
impl DebugToJson for f64
[src]
impl DebugToJson for f32
[src]
impl DebugToJson for bool
[src]
impl DebugToJson for char
[src]
impl DebugToJson for String
[src]
impl<T> DebugToJson for Box<T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for RwLock<T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for Mutex<T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for Rc<T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for Arc<T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for Option<T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for Vec<T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for HashSet<T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for LinkedList<T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for VecDeque<T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for BTreeSet<T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for HashMap<String, T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<T> DebugToJson for BTreeMap<String, T> where
T: DebugToJson,
[src]
T: DebugToJson,
impl<A, B> DebugToJson for (A, B) where
A: DebugToJson,
B: DebugToJson,
[src]
A: DebugToJson,
B: DebugToJson,
impl<A, B, C> DebugToJson for (A, B, C) where
A: DebugToJson,
B: DebugToJson,
C: DebugToJson,
[src]
Loading content...A: DebugToJson,
B: DebugToJson,
C: DebugToJson,