[−][src]Struct binjs::generic::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
F: Debug + PartialEq<F>,
I: Debug + PartialEq<I>,
[src]
F: Debug + PartialEq<F>,
I: Debug + PartialEq<I>,
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]
F: Clone,
I: Clone,
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]
F: Debug + PartialEq<F>,
I: Debug + PartialEq<I>,
impl<I, F> Clone for Path<I, F> where
F: Clone + Debug,
I: Clone + Debug,
[src]
F: Clone + Debug,
I: Clone + Debug,
impl<I, F> Debug for Path<I, F> where
F: Debug,
I: Debug,
[src]
F: Debug,
I: Debug,
impl<I, F> Default for Path<I, F> where
F: Default + Debug,
I: Default + Debug,
[src]
F: Default + Debug,
I: Default + Debug,
impl<'de, I, F> Deserialize<'de> for Path<I, F> where
F: Debug + Deserialize<'de>,
I: Debug + Deserialize<'de>,
[src]
F: Debug + Deserialize<'de>,
I: Debug + Deserialize<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Path<I, F>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
[src]
__deserializer: __D
) -> Result<Path<I, F>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
impl<I, F> Display for Path<I, F> where
F: Debug + Display,
I: Debug + Display,
[src]
F: Debug + Display,
I: Debug + Display,
impl<I, F> Eq for Path<I, F> where
F: Debug + Eq,
I: Debug + Eq,
[src]
F: Debug + Eq,
I: Debug + Eq,
impl<I, F> From<Vec<PathItem<I, F>>> for Path<I, F> where
F: Debug,
I: Debug,
[src]
F: Debug,
I: Debug,
impl<I, F> Hash for Path<I, F> where
F: Debug + Hash,
I: Debug + Hash,
[src]
F: Debug + Hash,
I: Debug + Hash,
fn hash<H>(&self, hasher: &mut H) where
H: Hasher,
[src]
H: Hasher,
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
F: Debug + PartialEq<F>,
I: Debug + PartialEq<I>,
[src]
F: Debug + PartialEq<F>,
I: Debug + PartialEq<I>,
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.
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<I, F> Serialize for Path<I, F> where
F: Debug + Serialize,
I: Debug + Serialize,
[src]
F: Debug + Serialize,
I: Debug + Serialize,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
[src]
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,