[−][src]Struct jsonp::Pointer
The heart of this library, this structure contains all of the base functionality to dereference into borrowed Json structures.
While this struct does not implement Copy
, it is extremely cheap to
clone and can be done liberally.
Implementations
impl Pointer
[src]
pub fn new(mode: Mode) -> Self
[src]
Instantiate a new pointer with the given mode
pub fn dotted<'de, 'j: 'de, J: ?Sized, T>(
&self,
backing: &'j J,
pointer: &str
) -> Result<T, J::Error> where
J: ToRaw<'j>,
T: Deserialize<'de>,
[src]
&self,
backing: &'j J,
pointer: &str
) -> Result<T, J::Error> where
J: ToRaw<'j>,
T: Deserialize<'de>,
Convenience function for using the common dot (.
) delimited format for dereferencing
nested Json structures.
Example
use jsonp::Pointer; let json = r#"{"outer": {"array": [0, "one", true]}}"#; let one: &str = Pointer::default().dotted(json, "outer.array.1").unwrap(); assert!(one == "one");
pub fn with_pattern<'de, 'j: 'de, J: ?Sized, T>(
&self,
backing: &'j J,
pointer: &str,
pattern: &str
) -> Result<T, J::Error> where
J: ToRaw<'j>,
T: Deserialize<'de>,
[src]
&self,
backing: &'j J,
pointer: &str,
pattern: &str
) -> Result<T, J::Error> where
J: ToRaw<'j>,
T: Deserialize<'de>,
Dereference using the given pointer and pattern. The pointer is split into
segments using the pattern. Starting the pointer with or without the pattern
is equivalent, i.e: with_pattern(..., ".foo", ".")
is equal to
with_pattern(..., "foo", ".")
.
Attempting to pass in either an empty pointer or pattern will cause this function
to short circuit any dereferencing and attempt deserialization from backing
directly.
Example
use jsonp::Pointer; let json = r#"{"outer": {"array": [0, "one", true]}}"#; let is_true: bool = Pointer::default().with_pattern(json, "outer array 2", " ").unwrap(); assert!(is_true);
pub fn with_segments<'de, 'j: 'de, 'p, J: ?Sized, I, T>(
&self,
backing: &'j J,
segments: I
) -> Result<T, J::Error> where
J: ToRaw<'j>,
I: IntoIterator<Item = Segment<'p>>,
T: Deserialize<'de>,
[src]
&self,
backing: &'j J,
segments: I
) -> Result<T, J::Error> where
J: ToRaw<'j>,
I: IntoIterator<Item = Segment<'p>>,
T: Deserialize<'de>,
Dereference using the given iterable set of segments.
Example
use jsonp::{Pointer, Segment}; let json = r#"{"outer": {"array": [0, 1, 2, 3]}}"#; let segments = &["outer", "array"]; let array: Vec<i8> = Pointer::default() .with_segments(json, segments.into_iter().copied().map(Segment::lazy)) .unwrap(); assert_eq!(&array, &[0, 1, 2, 3]);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Pointer
impl Send for Pointer
impl Sync for Pointer
impl Unpin for Pointer
impl UnwindSafe for Pointer
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,