Struct Context

Source
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>

Source

pub fn matches(&self, pattern: impl TryInto<ContextPattern<'src>>) -> bool

Returns whether the context matches the given pattern exactly.

Source

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.

Source

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.

Source

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§

Source§

impl<'src> Debug for Context<'src>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'src> PartialEq for Context<'src>

Source§

fn eq(&self, other: &Context<'src>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.