pub struct Program<O> {
pub steps: Vec<Step<O>>,
}Expand description
A recipe for building a Part: an ordered list of steps, each referring
to what earlier ones built only by name. Those names come from step ids
and sketch element ids, never from the internal ids a build happens to
assign (see geop_ops), so a program means the same thing every
time it is run — including after a round trip through JSON.
Fields§
§steps: Vec<Step<O>>Implementations§
Source§impl<O: Operations> Program<O>
impl<O: Operations> Program<O>
pub fn new() -> Self
Sourcepub fn push(&mut self, id: impl Into<String>, operation: impl Into<O>)
pub fn push(&mut self, id: impl Into<String>, operation: impl Into<O>)
Appends the step id: operation with its arguments.
Sourcepub fn index_of(&self, id: &str) -> GeopResult<usize>
pub fn index_of(&self, id: &str) -> GeopResult<usize>
The position of step id.
Sourcepub fn fresh_id(&self, operation: &O) -> String
pub fn fresh_id(&self, operation: &O) -> String
An id no step has yet, for a new step running operation: its
label, lowercased, and the lowest number that makes it unique —
sketch1, extrude2.
Sourcepub fn validate(&self) -> GeopResult<()>
pub fn validate(&self) -> GeopResult<()>
Checks that every step id is a valid operation id and unique: every name a step creates is built from its id.
Sourcepub fn build<S: Scalar>(&self) -> GeopResult<Part<S>>
pub fn build<S: Scalar>(&self) -> GeopResult<Part<S>>
Runs every step in order, starting from an empty part, and returns the part the whole program builds — or the first error any step raises, at which point the steps after it never run. A program always starts from nothing: its names are only guaranteed to be unique, and to mean the same thing on every run, when every entity was created by one of its own steps.
After each step, every entity of the part must have a name — an operation that leaves one unnamed has broken the one guarantee a program relies on.
Sourcepub fn to_json(&self) -> GeopResult<String>
pub fn to_json(&self) -> GeopResult<String>
The program as pretty-printed JSON: one step per object, every sketch entity keyed by its id, so edits show up as small line diffs.