[][src]Struct jsonp::BackingBytes

pub struct BackingBytes<'a> { /* fields omitted */ }

Convenience wrapper around the library core functions for byte slices, removing some of the generic noise from function signatures.

Implementations

impl<'a> BackingBytes<'a>[src]

pub fn new(borrow: &'a [u8]) -> Self[src]

Instantiate a wrapper around the given byte slice.

pub fn with(borrow: &'a [u8], pointer: Pointer) -> Self[src]

Instantiate a wrapper around the given byte slice and pointer.

pub fn dotted<'de, T>(&self, pointer: &str) -> Result<T, Error> where
    T: Deserialize<'de>,
    'a: 'de, 
[src]

See the documentation of Pointer::dotted.

Example

use jsonp::BackingBytes;

fn main() {
    let json = r#"{"outer": {"array": [0, "one", true]}}"#.as_bytes();
    let one: &str = BackingBytes::new(json).dotted("outer.array.1").unwrap();

    assert!(one == "one");
}

pub fn pattern<'de, T>(&self, pointer: &str, pattern: &str) -> Result<T, Error> where
    T: Deserialize<'de>,
    'a: 'de, 
[src]

See the documentation of Pointer::with_pattern.

Example

use jsonp::BackingBytes;
fn main() {
    let json = r#"{"outer": {"array": [0, "one", true]}}"#.as_bytes();
    let is_true: bool = BackingBytes::new(json).pattern("outer array 2", " ").unwrap();

    assert!(is_true);
}

pub fn pointer<'de, 'p, I, T>(&self, pointers: I) -> Result<T, Error> where
    I: IntoIterator<Item = Segment<'p>>,
    T: Deserialize<'de>,
    'a: 'de, 
[src]

See the documentation for Pointer::with_segments.

Example

use jsonp::{BackingBytes, Segment};
fn main() {
    let json = r#"{"outer": {"array": [0, 1, 2, 3]}}"#.as_bytes();
    let segments = &["outer", "array"];
    let array: Vec<i8> = BackingBytes::new(json)
        .pointer(segments.into_iter().copied().map(Segment::lazy))
        .unwrap();

    assert_eq!(&array, &[0, 1, 2, 3]);
}

Trait Implementations

impl<'a> Clone for BackingBytes<'a>[src]

impl<'a> Debug for BackingBytes<'a>[src]

impl<'a> From<&'a [u8]> for BackingBytes<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for BackingBytes<'a>

impl<'a> Send for BackingBytes<'a>

impl<'a> Sync for BackingBytes<'a>

impl<'a> Unpin for BackingBytes<'a>

impl<'a> UnwindSafe for BackingBytes<'a>

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.