pub struct BackingJson<'a> { /* private fields */ }Expand description
Convenience wrapper around the library core functions for raw Json, removing some of the generic noise from function signatures.
Implementations§
Source§impl<'a> BackingJson<'a>
impl<'a> BackingJson<'a>
Sourcepub fn new(borrow: &'a RawJson) -> Self
pub fn new(borrow: &'a RawJson) -> Self
Instantiate a wrapper around the given borrowed raw Json.
Sourcepub fn with(borrow: &'a RawJson, p: Pointer) -> Self
pub fn with(borrow: &'a RawJson, p: Pointer) -> Self
Instantiate a wrapper around the given borrowed raw Json and pointer.
Sourcepub fn dotted<'de, T>(&self, pointer: &str) -> Result<T, Error>where
T: Deserialize<'de>,
'a: 'de,
pub fn dotted<'de, T>(&self, pointer: &str) -> Result<T, Error>where
T: Deserialize<'de>,
'a: 'de,
See the documentation of Pointer::dotted.
§Example
use {jsonp::{BackingJson, Segment}, serde_json::from_str};
let json = from_str(r#"{"outer": {"array": [0, "one", true]}}"#).unwrap();
let one: &str = BackingJson::new(json).dotted("outer.array.1").unwrap();
assert!(one == "one");Sourcepub fn pattern<'de, T>(&self, pointer: &str, pattern: &str) -> Result<T, Error>where
T: Deserialize<'de>,
'a: 'de,
pub fn pattern<'de, T>(&self, pointer: &str, pattern: &str) -> Result<T, Error>where
T: Deserialize<'de>,
'a: 'de,
See the documentation of Pointer::with_pattern.
§Example
use {jsonp::{BackingJson, Segment}, serde_json::from_str};
let json = from_str(r#"{"outer": {"array": [0, "one", true]}}"#).unwrap();
let is_true: bool = BackingJson::new(json).pattern("outer array 2", " ").unwrap();
assert!(is_true);Sourcepub fn pointer<'de, 'p, I, T>(&self, pointers: I) -> Result<T, Error>
pub fn pointer<'de, 'p, I, T>(&self, pointers: I) -> Result<T, Error>
See the documentation for Pointer::with_segments.
§Example
use {jsonp::{BackingJson, Segment}, serde_json::from_str};
let json = from_str(r#"{"outer": {"array": [0, 1, 2, 3]}}"#).unwrap();
let segments = &["outer", "array"];
let array: Vec<i8> = BackingJson::new(json)
.pointer(segments.into_iter().copied().map(Segment::lazy))
.unwrap();
assert_eq!(&array, &[0, 1, 2, 3]);Trait Implementations§
Source§impl<'a> Clone for BackingJson<'a>
impl<'a> Clone for BackingJson<'a>
Source§fn clone(&self) -> BackingJson<'a>
fn clone(&self) -> BackingJson<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for BackingJson<'a>
impl<'a> Debug for BackingJson<'a>
Auto Trait Implementations§
impl<'a> Freeze for BackingJson<'a>
impl<'a> RefUnwindSafe for BackingJson<'a>
impl<'a> Send for BackingJson<'a>
impl<'a> Sync for BackingJson<'a>
impl<'a> Unpin for BackingJson<'a>
impl<'a> UnwindSafe for BackingJson<'a>
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