pub struct Clause {
pub vars: Vec<String>,
pub source: ClauseSource,
}Expand description
One clause of a comprehension: one or more variable names paired with their source expression(s).
Single-var clause (the common case): one variable
binds successive values from one source list.
Clause::new("k", "1..10") is the construction shortcut.
Parallel clause (SRD-18c Layer 7a): multiple
variables advance in lockstep (“zip”) from multiple
source expressions. Clause::parallel(["x", "y"], ["1..10", "100..1000..100"]) builds the parallel form.
The string fields are owned because the AST gets stored on long-lived scope-tree / scenario-tree nodes; sharing references back into the source text would force lifetimes through every consumer.
Fields§
§vars: Vec<String>The element names the clause binds.
source: ClauseSourceWhere the values come from.
Implementations§
Source§impl Clause
impl Clause
Sourcepub fn new(var: impl Into<String>, expr: impl Into<String>) -> Clause
pub fn new(var: impl Into<String>, expr: impl Into<String>) -> Clause
Single-var construction: Clause::new("k", "1..10").
Backward-compatible with the pre-Layer-7a shape — every
existing call site works unchanged.
Sourcepub fn parallel(
vars: impl IntoIterator<Item = impl Into<String>>,
exprs: impl IntoIterator<Item = impl Into<String>>,
) -> Clause
pub fn parallel( vars: impl IntoIterator<Item = impl Into<String>>, exprs: impl IntoIterator<Item = impl Into<String>>, ) -> Clause
Parallel-iter construction (SRD-18c Layer 7a):
Clause::parallel(["x", "y"], ["1..10", "fib(8)"]).
Defaults to ZipMode::Strict — length mismatch
across the parallel group is an iteration-time error.
Use Clause::parallel_with_mode to opt into
truncate / cycle.
Length mismatch between vars and exprs is a
programming error and panics — the parser’s input
validation should catch malformed user input before
it reaches this constructor.
Sourcepub fn parallel_with_mode(
mode: ZipMode,
vars: impl IntoIterator<Item = impl Into<String>>,
exprs: impl IntoIterator<Item = impl Into<String>>,
) -> Clause
pub fn parallel_with_mode( mode: ZipMode, vars: impl IntoIterator<Item = impl Into<String>>, exprs: impl IntoIterator<Item = impl Into<String>>, ) -> Clause
Parallel-iter construction with explicit zip mode.
See ZipMode.
Sourcepub fn single_var(&self) -> Option<&str>
pub fn single_var(&self) -> Option<&str>
Single-var convenience: returns the lone variable
name when the clause is single-var. None for
parallel-iter forms — those have multiple names.
Sourcepub fn single_expr(&self) -> Option<&str>
pub fn single_expr(&self) -> Option<&str>
Single-source convenience: returns the lone source
expression when the clause uses ClauseSource::Single.
None for parallel forms.
Sourcepub fn is_parallel(&self) -> bool
pub fn is_parallel(&self) -> bool
True for parallel-iter clauses (Layer 7a).
Sourcepub fn first_var(&self) -> &str
pub fn first_var(&self) -> &str
Backward-compat accessor: returns the first variable
name regardless of clause shape. Single-var clauses
have vars.len() == 1; parallel clauses have ≥ 2.
Most existing callers operate on single-var clauses
and treat parallel forms as either-or — those should
migrate to single_var() for explicit handling.
Sourcepub fn var(&self) -> &str
pub fn var(&self) -> &str
Convenience for single-var clauses (the historical
common case): the lone variable name. For parallel
clauses, returns the first variable’s name. Most
existing call sites treat clauses as single-var; this
keeps them working with a one-line c.var →
c.var() migration.
Sourcepub fn expr(&self) -> &str
pub fn expr(&self) -> &str
Convenience for single-source clauses: the lone source-expression text. For parallel clauses, returns the first expression — single-var-assuming callers see the same shape they did before Layer 7a.
Sourcepub fn scalar_bindings(&self) -> Vec<(&str, &str)>
pub fn scalar_bindings(&self) -> Vec<(&str, &str)>
Flatten this clause to its scalar (var, expr) pairs.
- Single-var (
vars = [v],Single(s)): returns[(v, s)]. - Parallel-iter (
vars = [v0, v1, ...],Parallel { exprs: [e0, e1, ...], .. }): returns[(v0, e0), (v1, e1), ...].
One canonical place to expand the var↔expr mapping — previously open-coded at three callers (synthesis representative-vars expansion, runner canonical-input declaration, runner param-ref scan).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Clause
impl<'de> Deserialize<'de> for Clause
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Clause, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Clause, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for Clause
Canonical text rendering of a clause:
impl Display for Clause
Canonical text rendering of a clause:
- Single-var:
var in expr. - Parallel-iter:
(a, b) in (e1, e2)forZipMode::Strict,zip_truncate(...)/zip_cycle(...)for the other modes.
parse_clause(&clause.to_string()) round-trips back to the
same AST.
impl Eq for Clause
Source§impl Serialize for Clause
impl Serialize for Clause
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Clause
Auto Trait Implementations§
impl Freeze for Clause
impl RefUnwindSafe for Clause
impl Send for Clause
impl Sync for Clause
impl Unpin for Clause
impl UnsafeUnpin for Clause
impl UnwindSafe for Clause
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more