[][src]Struct binjs_shared::ast::Path

pub struct Path<I, F> where
    I: Debug,
    F: Debug
{ /* fields omitted */ }

The path followed when walking an AST.

Designed to be used both to quickly find out how to contextually handle a specific node and for error-reporting.

use binjs_shared::ast::Path;

let mut path = Path::new();
assert!(path.get(0).is_none());

// Once we have entered both an interface and a field, `path.get(0)` will be `Some`.
path.enter_interface("Interface 1");
assert!(path.get(0).is_none());

path.enter_field("Field 1");

{
  let item = path.get(0).unwrap();
  assert_eq!(item.field, "Field 1");
  assert_eq!(item.interface, "Interface 1");
}

path.enter_interface("Interface 2");
path.enter_field("Field 2");

{
  let item = path.get(0).unwrap();
  assert_eq!(item.field, "Field 2");
  assert_eq!(item.interface, "Interface 2");
}
{
  let item = path.get(1).unwrap();
  assert_eq!(item.field, "Field 1");
  assert_eq!(item.interface, "Interface 1");
}

// We need to exit the field before exiting the interface.
path.exit_field("Field 2"); // Exiting the wrong field would panic.
path.exit_interface("Interface 2"); // Exiting the wrong interface would panic.
path.exit_field("Field 1"); // Exiting the wrong field would panic.
path.exit_interface("Interface 1"); // Exiting the wrong interface would panic.

Methods

impl<I, F> Path<I, F> where
    I: Debug + PartialEq,
    F: Debug + PartialEq
[src]

pub fn new() -> Self[src]

Create an empty Path.

pub fn extend_from_slice(&mut self, slice: &[PathItem<I, F>]) where
    I: Clone,
    F: Clone
[src]

pub fn with_capacity(capacity: usize) -> Self[src]

Create an empty Path, initialized to hold up to capacity elements without resize.

pub fn enter_interface(&mut self, node: I)[src]

Enter an interface.

All calls to enter_interface MUST be balanced with calls to exit_interface.

pub fn exit_interface(&mut self, node: I)[src]

pub fn enter_field(&mut self, field: F)[src]

pub fn exit_field(&mut self, field: F)[src]

pub fn len(&self) -> usize[src]

pub fn get(&self, index: usize) -> Option<&PathItem<I, F>>[src]

pub fn tail(&self, len: usize) -> &[PathItem<I, F>][src]

Return the last len elements of the path, in the order in which they appear in the path (current element is last).

If there are fewer than len elements, return as many elements as possible.

pub fn iter(&self) -> impl Iterator<Item = &PathItem<I, F>>[src]

Iter through the path, from the root to the current position.

Trait Implementations

impl<I, F> Borrow<[PathItem<I, F>]> for Path<I, F> where
    I: Debug + PartialEq,
    F: Debug + PartialEq
[src]

impl<I: Clone, F: Clone> Clone for Path<I, F> where
    I: Debug,
    F: Debug
[src]

impl<I, F> Debug for Path<I, F> where
    I: Debug,
    F: Debug
[src]

impl<I: Default, F: Default> Default for Path<I, F> where
    I: Debug,
    F: Debug
[src]

impl<'de, I, F> Deserialize<'de> for Path<I, F> where
    I: Debug,
    F: Debug,
    I: Deserialize<'de>,
    F: Deserialize<'de>, 
[src]

impl<I, F> Display for Path<I, F> where
    I: Debug + Display,
    F: Debug + Display
[src]

impl<I, F> Eq for Path<I, F> where
    I: Debug + Eq,
    F: Debug + Eq
[src]

impl<I, F> From<Vec<PathItem<I, F>>> for Path<I, F> where
    I: Debug,
    F: Debug
[src]

impl<I, F> Hash for Path<I, F> where
    I: Debug + Hash,
    F: Debug + Hash
[src]

fn hash<H: Hasher>(&self, hasher: &mut H)[src]

As we implement Borrow<[PathItem<...>] for Path, we must ensure that Hash gives the same result for a Path and its [PathItem] representation.

impl<I, F> PartialEq<Path<I, F>> for Path<I, F> where
    I: Debug + PartialEq,
    F: Debug + PartialEq
[src]

fn eq(&self, other: &Self) -> bool[src]

As we implement Borrow<[PathItem<...>] for Path, we must ensure that Eq gives the same result for a Eq and its [PathItem] representation.

impl<I, F> Serialize for Path<I, F> where
    I: Debug,
    F: Debug,
    I: Serialize,
    F: Serialize
[src]

Auto Trait Implementations

impl<I, F> RefUnwindSafe for Path<I, F> where
    F: RefUnwindSafe,
    I: RefUnwindSafe

impl<I, F> Send for Path<I, F> where
    F: Send,
    I: Send

impl<I, F> Sync for Path<I, F> where
    F: Sync,
    I: Sync

impl<I, F> Unpin for Path<I, F> where
    F: Unpin,
    I: Unpin

impl<I, F> UnwindSafe for Path<I, F> where
    F: UnwindSafe,
    I: UnwindSafe

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> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> Downcast for T where
    T: Any
[src]

impl<T> DowncastSync for T where
    T: Send + Sync + Any
[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> ToString for T where
    T: Display + ?Sized
[src]

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.