[][src]Struct jsonp::Pointer

pub struct Pointer { /* fields omitted */ }

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]

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]

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]

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

impl Clone for Pointer[src]

impl Debug for Pointer[src]

impl Default for Pointer[src]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.