pub struct Context<'src> {
pub parts: Vec<SpannedExpr<'src>>,
}
Expand description
Represents a context in a GitHub Actions expression.
These typically look something like github.actor
or inputs.foo
,
although they can also be a “call” context like fromJSON(...).foo.bar
,
i.e. where the head of the context is a function call rather than an
identifier.
Fields§
§parts: Vec<SpannedExpr<'src>>
The individual parts of the context.
Implementations§
Source§impl<'src> Context<'src>
impl<'src> Context<'src>
Sourcepub fn matches(&self, pattern: impl TryInto<ContextPattern<'src>>) -> bool
pub fn matches(&self, pattern: impl TryInto<ContextPattern<'src>>) -> bool
Returns whether the context matches the given pattern exactly.
Sourcepub fn child_of(&self, parent: impl TryInto<ContextPattern<'src>>) -> bool
pub fn child_of(&self, parent: impl TryInto<ContextPattern<'src>>) -> bool
Returns whether the context is a child of the given pattern.
A context is considered its own child, i.e. foo.bar
is a child of
foo.bar
.
Sourcepub fn single_tail(&self) -> Option<&str>
pub fn single_tail(&self) -> Option<&str>
Return this context’s “single tail,” if it has one.
This is useful primarily for contexts under env
and inputs
,
where we expect only a single tail part, e.g. env.FOO
or
inputs['bar']
.
Returns None
if the context has more than one tail part,
or if the context’s head part is not an identifier.
Sourcepub fn as_pattern(&self) -> Option<String>
pub fn as_pattern(&self) -> Option<String>
Returns the “pattern equivalent” of this context.
This is a string that can be used to efficiently match the context,
such as is done in zizmor
’s template-injection audit via a
finite state transducer.
Returns None if the context doesn’t have a sensible pattern equivalent, e.g. if it starts with a call.
Trait Implementations§
impl<'src> StructuralPartialEq for Context<'src>
Auto Trait Implementations§
impl<'src> Freeze for Context<'src>
impl<'src> RefUnwindSafe for Context<'src>
impl<'src> Send for Context<'src>
impl<'src> Sync for Context<'src>
impl<'src> Unpin for Context<'src>
impl<'src> UnwindSafe for Context<'src>
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> 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