pub struct Json<T>(pub T);Expand description
A marker struct that enables JSON parsing and generation through the FromStr and Display traits.
This provides a convenient way to work with JSON, but if you need more fine-grained control,
consider using RawJson (for JSON parsing) and json() (for JSON generation) instead.
§Examples
Parsing JSON text:
use nojson::Json;
// Since the `[Option<u32>; 3]` type implements `TryFrom<RawJsonValue<'_, '_>>`,
// you can use the `std::str::parse()` method to parse JSON by wrapping the type with `Json`.
let text = "[1, null, 2]";
let value: Json<[Option<u32>; 3]> = text.parse()?;
assert_eq!(value.0, [Some(1), None, Some(2)]);Generating JSON from a Rust type:
use nojson::Json;
// Since the `[Option<u32>; 3]` type also implements the `DisplayJson` trait,
// you can use the `std::fmt::Display::to_string()` method to
// generate JSON by wrapping the type with `Json`.
let value = [Some(1), None, Some(2)];
assert_eq!(Json(value).to_string(), "[1,null,2]");Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: DisplayJson> Display for Json<T>
impl<T: DisplayJson> Display for Json<T>
Source§impl<T: Ord> Ord for Json<T>
impl<T: Ord> Ord for Json<T>
Source§impl<T: PartialOrd> PartialOrd for Json<T>
impl<T: PartialOrd> PartialOrd for Json<T>
impl<T: Copy> Copy for Json<T>
impl<T: Eq> Eq for Json<T>
impl<T> StructuralPartialEq for Json<T>
Auto Trait Implementations§
impl<T> Freeze for Json<T>where
T: Freeze,
impl<T> RefUnwindSafe for Json<T>where
T: RefUnwindSafe,
impl<T> Send for Json<T>where
T: Send,
impl<T> Sync for Json<T>where
T: Sync,
impl<T> Unpin for Json<T>where
T: Unpin,
impl<T> UnwindSafe for Json<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more