[][src]Struct binjs::generic::ast::Path

pub struct Path<I, F> where
    F: Debug,
    I: 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
    F: Debug + PartialEq<F>,
    I: Debug + PartialEq<I>, 
[src]

pub fn new() -> Path<I, F>[src]

Create an empty Path.

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

pub fn with_capacity(capacity: usize) -> Path<I, F>[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
    F: Debug + PartialEq<F>,
    I: Debug + PartialEq<I>, 
[src]

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

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

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

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

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

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

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

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

fn hash<H>(&self, hasher: &mut H) where
    H: Hasher
[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
    F: Debug + PartialEq<F>,
    I: Debug + PartialEq<I>, 
[src]

fn eq(&self, other: &Path<I, F>) -> 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
    F: Debug + Serialize,
    I: Debug + 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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]