pub enum FieldPathElem<'ast> {
Ident(LocIdent),
Expr(Ast<'ast>),
}Expand description
Element of a record field path in a record field definition. For example, in { a."%{"hello-" ++ "world"}".c = true }, the path a."%{b}".c is composed of three elements: an identifier
a, an expression "hello" ++ "world", and another identifier c.
Variants§
Ident(LocIdent)
A statically known identifier.
Expr(Ast<'ast>)
A dynamic field name written as a quoted expression, e.g. "%{protocol}" = .. . Normally,
the expression must be a crate::ast::Node::StringChunks, so we could store the
chunks directly which would be more precise. However, it’s useful to keep a general
crate::ast::Ast to store errors when part of the field path failed to parse
correctly.
Implementations§
Source§impl<'ast> FieldPathElem<'ast>
impl<'ast> FieldPathElem<'ast>
Sourcepub fn expr(expr: Ast<'ast>) -> Self
pub fn expr(expr: Ast<'ast>) -> Self
Build a field path element from an expression. Automatically convert an expression that is actually a static identifier to Self::Ident.
Sourcepub fn single_ident_path(
alloc: &'ast AstAlloc,
ident: LocIdent,
) -> &'ast [FieldPathElem<'ast>]
pub fn single_ident_path( alloc: &'ast AstAlloc, ident: LocIdent, ) -> &'ast [FieldPathElem<'ast>]
Crate a path composed of a single static identifier.
Sourcepub fn single_expr_path(
alloc: &'ast AstAlloc,
expr: Ast<'ast>,
) -> &'ast [FieldPathElem<'ast>]
pub fn single_expr_path( alloc: &'ast AstAlloc, expr: Ast<'ast>, ) -> &'ast [FieldPathElem<'ast>]
Create a path composed of a single dynamic expression.
Sourcepub fn try_as_ident(&self) -> Option<LocIdent>
pub fn try_as_ident(&self) -> Option<LocIdent>
Try to interpret this element as a static identifier. Returns None if the element
is an expression with interpolation inside. Dual of Self::try_as_dyn_expr.
We assume that the parser has already normalized expressions that are actually static identifiers. So this method is a simple selector over Self::Ident.
Sourcepub fn try_as_dyn_expr(&self) -> Option<&Ast<'ast>>
pub fn try_as_dyn_expr(&self) -> Option<&Ast<'ast>>
Tries to interpret this element as a dynamic identifier. Returns None if the element is a
static identifier (that is, if Self::try_as_ident returns Some(_)).
Trait Implementations§
Source§impl<'ast> Clone for FieldPathElem<'ast>
impl<'ast> Clone for FieldPathElem<'ast>
Source§fn clone(&self) -> FieldPathElem<'ast>
fn clone(&self) -> FieldPathElem<'ast>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl CloneTo for FieldPathElem<'_>
impl CloneTo for FieldPathElem<'_>
Source§type Data<'ast> = FieldPathElem<'ast>
type Data<'ast> = FieldPathElem<'ast>
Self, be we need associated types to make Rust understand that Self is
always parametric over the 'ast lifetime. We’re using GATs to emulate higher-kinded
types.Source§impl<'ast> Debug for FieldPathElem<'ast>
impl<'ast> Debug for FieldPathElem<'ast>
Source§impl<'ast> PartialEq for FieldPathElem<'ast>
impl<'ast> PartialEq for FieldPathElem<'ast>
Source§impl<'a> Pretty<'a, Allocator> for &FieldPathElem<'_>
impl<'a> Pretty<'a, Allocator> for &FieldPathElem<'_>
impl Allocable for FieldPathElem<'_>
impl<'ast> Eq for FieldPathElem<'ast>
impl<'ast> StructuralPartialEq for FieldPathElem<'ast>
Auto Trait Implementations§
impl<'ast> Freeze for FieldPathElem<'ast>
impl<'ast> RefUnwindSafe for FieldPathElem<'ast>
impl<'ast> Send for FieldPathElem<'ast>
impl<'ast> Sync for FieldPathElem<'ast>
impl<'ast> Unpin for FieldPathElem<'ast>
impl<'ast> UnsafeUnpin for FieldPathElem<'ast>
impl<'ast> UnwindSafe for FieldPathElem<'ast>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more