pub struct Pointer<'a>(_);
Expand description

Pointer, a JSON pointer representation based on RFC6901.

This type offers strong ordering over the underlying Unicode string:

  • JSON pointers are sorted by ascending depth.
  • JSON pointers with the same depth are alphanumerically sorted.

Implementations

Creates a Pointer from a Unicode string as describe in RFC6901.

Arguments
  • s: A Unicode string representing a JSON pointer.
Examples

// Construct a `Pointer` from a string literal.
let pointer = Pointer::new("/a/b/c").unwrap();

// Construct a `Pointer` from a owned string.
let pointer = Pointer::new(String::from("/a/b/c")).unwrap();

Creates a root JSON pointer.

Indicates if the JSON pointer points to root value.

Returns the Unicode string representation of the JSON pointer.

Returns the last reference token of the JSON pointer, also called JSON key.

Note that the root pointer does not contains any reference tokens and so no JSON key.

Example

let pointer = Pointer::new("/key").unwrap();
assert_eq!(pointer.key(), Some("key".to_string()));

let pointer = Pointer::root();
assert!(pointer.key().is_none());

Returns the parent JSON pointer.

Note that the returned JSON pointer borrows a part of the underlying Unicode string then it can be clone without any extra allocation.

Example

let pointer = Pointer::new("/nested/key").unwrap();
let parent_pointer = Pointer::new("/nested").unwrap();

assert_eq!(pointer.parent(), Some(parent_pointer));

Produces an iterator over Pointer and its parent JSON pointers.

As Pointer::parent method, all the returned JSON pointers borrow parts of the underlying Unicode string then any of them can be clone without any extra allocation.

The iterator will yield the Pointer then its parents like self, self.parent().unwrap(), self.parent().unwrap().parent().unwrap() and so on until reaching the root JSON pointer.

Examples

let pointer = Pointer::new("/foo/bar/zoo").unwrap();
let ancestors = pointer.ancestors().collect::<Vec<_>>();

assert_eq!(
    ancestors,
    vec![
        Pointer::new("/foo/bar/zoo").unwrap(),
        Pointer::new("/foo/bar").unwrap(),
        Pointer::new("/foo").unwrap(),
        Pointer::root()
    ]
);

Indicates if Pointer is an ancestor of the given JSON pointer.

Note that Pointer is an ancestor of itself.

Indicates if Pointer is a parent of the given JSON pointer.

Note that the root JSON pointer is the only one with no parent.

Indicates if Pointer is a sibling of the given JSON pointer.

Indicates the number of reference tokens in the JSON pointer, in a zero-based indexed way.

Creates an owned instance of Pointer.

Note that this function may call Clone::clone if the underlying Unicode string is borrowed.

Evaluates Pointer into tokens as define in RFC6901.

Examples

let pointer = Pointer::new("/~1foo/~0bar/zoo").unwrap();
let tokens = pointer.tokenize().collect::<Vec<_>>();

assert_eq!(
    tokens,
    vec![
        "/foo".to_string(),
        "~bar".to_string(),
        "zoo".to_string(),
    ]
);

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.