Skip to main content

Path

Struct Path 

Source
pub struct Path<'a> { /* private fields */ }
Expand description

A parsed path.

Parsing is separate from matching because a path arrives once and is matched against every document a command touches, and because a path that does not parse should be an error before any document is read rather than an empty answer after all of them.

Implementations§

Source§

impl<'a> Path<'a>

Source

pub fn parse(path: &'a [u8]) -> Result<Path<'a>>

Parse path.

A path that starts with $ is a JSONPath and anything else is what RedisJSON calls a legacy path, which is the older syntax that answers one value. Both are matched the same way here and the difference is recorded in Path::legacy, because what it changes is the shape of the reply and that is the dispatch layer’s business rather than this one’s.

Source

pub fn is_projection(&self) -> bool

Whether this path is an expression rather than a way through the document.

A projection answers values that are nowhere in the document, so there is nothing for a write to write to and nothing for JSON.TYPE to describe. Only JSON.GET, JSON.MGET and JSON.RESP take one and the rest refuse it, which is what this is for.

Source

pub fn project<'d>(&'d self, root: &Value<'d>) -> Vec<Computed<'d>>

What this projection works out against root, and nothing at all when the path is not one.

Source

pub fn legacy(&self) -> bool

Whether this path was written in the older syntax, without a leading $.

Source

pub fn is_root(&self) -> bool

Whether this path is the root and nothing else.

$, a bare . and the empty path are all it. JSON.SET needs to know, because the root is the only place a whole document can be written to a key that is not there yet, and JSON.DEL needs to know because deleting the root is deleting the key.

Source

pub fn is_definite(&self) -> bool

Whether this path names at most one place, whatever document it is matched against.

A path made only of names and indices does. Everything else can answer more than one value on some document even if it answers one on this one, and the difference decides what a command is allowed to do: JSON.SET creating a field that is not there yet only makes sense when the path says exactly where it goes.

Source

pub fn select<'d>(&self, root: &Value<'d>, out: &mut Vec<Value<'d>>)

Every value this path names in root, in document order, appended to out.

Appended rather than assigned, so that a command matching one path against many documents keeps one buffer. Nothing here allocates except that buffer and the frontier the walk carries.

Source

pub fn split_last(&self) -> Option<(Path<'a>, Step<'a>)>

This path without its last selector, and that selector, when the last one names one place.

JSON.SET is what needs it. A path that matched nothing can still be a place to write, as long as what would hold the new value is there and the last step says exactly where in it the value goes, so $.a.b against a document with an a and no b splits into the parent $.a and the step b.

None for the root, which has no last selector, and for a last selector that is a wildcard, a descent, a union or a slice, because none of those names a place that is not already there.

Source

pub fn first<'d>(&self, root: &Value<'d>) -> Option<Value<'d>>

The one value this path names, for a caller that has already checked Path::is_definite or that only wants the first of several.

RedisJSON’s older syntax answers the first match, which is what this is for.

Trait Implementations§

Source§

impl<'a> Clone for Path<'a>

Source§

fn clone(&self) -> Path<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Path<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Path<'a>

§

impl<'a> RefUnwindSafe for Path<'a>

§

impl<'a> Send for Path<'a>

§

impl<'a> Sync for Path<'a>

§

impl<'a> Unpin for Path<'a>

§

impl<'a> UnsafeUnpin for Path<'a>

§

impl<'a> UnwindSafe for Path<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.