[−][src]Struct binjs_shared::ast::Path
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]
I: Debug + PartialEq,
F: Debug + PartialEq,
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]
I: Clone,
F: Clone,
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]
I: Debug + PartialEq,
F: Debug + PartialEq,
impl<I: Clone, F: Clone> Clone for Path<I, F> where
I: Debug,
F: Debug,
[src]
I: Debug,
F: Debug,
impl<I, F> Debug for Path<I, F> where
I: Debug,
F: Debug,
[src]
I: Debug,
F: Debug,
impl<I: Default, F: Default> Default for Path<I, F> where
I: Debug,
F: Debug,
[src]
I: Debug,
F: Debug,
impl<'de, I, F> Deserialize<'de> for Path<I, F> where
I: Debug,
F: Debug,
I: Deserialize<'de>,
F: Deserialize<'de>,
[src]
I: Debug,
F: Debug,
I: Deserialize<'de>,
F: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<I, F> Display for Path<I, F> where
I: Debug + Display,
F: Debug + Display,
[src]
I: Debug + Display,
F: Debug + Display,
impl<I, F> Eq for Path<I, F> where
I: Debug + Eq,
F: Debug + Eq,
[src]
I: Debug + Eq,
F: Debug + Eq,
impl<I, F> From<Vec<PathItem<I, F>>> for Path<I, F> where
I: Debug,
F: Debug,
[src]
I: Debug,
F: Debug,
impl<I, F> Hash for Path<I, F> where
I: Debug + Hash,
F: Debug + Hash,
[src]
I: Debug + Hash,
F: Debug + Hash,
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.
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<I, F> PartialEq<Path<I, F>> for Path<I, F> where
I: Debug + PartialEq,
F: Debug + PartialEq,
[src]
I: Debug + PartialEq,
F: Debug + PartialEq,
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.
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<I, F> Serialize for Path<I, F> where
I: Debug,
F: Debug,
I: Serialize,
F: Serialize,
[src]
I: Debug,
F: Debug,
I: Serialize,
F: Serialize,
Auto Trait Implementations
impl<I, F> RefUnwindSafe for Path<I, F> where
F: RefUnwindSafe,
I: RefUnwindSafe,
F: RefUnwindSafe,
I: RefUnwindSafe,
impl<I, F> Send for Path<I, F> where
F: Send,
I: Send,
F: Send,
I: Send,
impl<I, F> Sync for Path<I, F> where
F: Sync,
I: Sync,
F: Sync,
I: Sync,
impl<I, F> Unpin for Path<I, F> where
F: Unpin,
I: Unpin,
F: Unpin,
I: Unpin,
impl<I, F> UnwindSafe for Path<I, F> where
F: UnwindSafe,
I: UnwindSafe,
F: UnwindSafe,
I: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> Downcast for T where
T: Any,
[src]
T: Any,
fn into_any(self: Box<T>) -> Box<dyn Any + 'static>
[src]
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
[src]
fn as_any(&self) -> &(dyn Any + 'static)
[src]
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
[src]
impl<T> DowncastSync for T where
T: Send + Sync + Any,
[src]
T: Send + Sync + Any,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,