pub struct Program {
pub steps: Vec<ProgramStep>,
pub state: StateValues,
pub display: Display,
}Expand description
A program: its steps, the state it was saved with — what it is run
with: what a solve moves (see Program::run) — and how what it
builds is shown.
Fields§
§steps: Vec<ProgramStep>§state: StateValues§display: DisplayImplementations§
Source§impl Program
impl Program
Sourcepub fn from_steps(steps: Vec<ProgramStep>) -> Self
pub fn from_steps(steps: Vec<ProgramStep>) -> Self
The program of steps, with no state.
Sourcepub fn from_json(text: &str) -> GeopResult<Self>
pub fn from_json(text: &str) -> GeopResult<Self>
The program the file text holds, its ids checked (see
Program::validate_ids). What its steps are is checked against
the operations they are run in (Program::validate). An empty
file, as one is when just made, is the empty program.
pub fn to_json(&self) -> GeopResult<String>
Sourcepub fn step(&self, id: &str) -> GeopResult<&ProgramStep>
pub fn step(&self, id: &str) -> GeopResult<&ProgramStep>
The step id.
pub fn step_mut(&mut self, id: &str) -> GeopResult<&mut ProgramStep>
Sourcepub fn index_of(&self, id: &str) -> GeopResult<usize>
pub fn index_of(&self, id: &str) -> GeopResult<usize>
The position of the step id.
Sourcepub fn push<A: StepArgs>(&mut self, id: impl Into<String>, args: A)
pub fn push<A: StepArgs>(&mut self, id: impl Into<String>, args: A)
Appends the step id, args for the operation they are for: for a
program written in Rust, whose arguments are plain data.
Sourcepub fn fresh_id(&self, label: &str) -> String
pub fn fresh_id(&self, label: &str) -> String
An id no step has yet, for a new step of an operation labelled
label: the label, lowercased, and the lowest number that makes it
unique — sketch1, extrude2.
Sourcepub fn run(&self, runner: &Runner, part: &mut Part) -> GeopResult<()>
pub fn run(&self, runner: &Runner, part: &mut Part) -> GeopResult<()>
Runs it all on part, which keeps what earlier runs built, by
runner (see Runner::run). Fails naming the first step that
does.
Sourcepub fn excerpt(&self, id: &str) -> GeopResult<Self>
pub fn excerpt(&self, id: &str) -> GeopResult<Self>
The step id as a program of its own, as a copy of it is kept: the
step, and the state that is its, every key naming it (names_step):
where a placed part is, how its joints are turned.
Sourcepub fn rewrite_texts(&mut self, rewrite: impl Fn(&str) -> Option<String>)
pub fn rewrite_texts(&mut self, rewrite: impl Fn(&str) -> Option<String>)
Every text in its steps’ arguments that rewrite rewrites,
rewritten: the files they name, as the steps move to another file.
Sourcepub fn paste(
&mut self,
pasted: Self,
index: usize,
registry: &OperationRegistry,
label: impl Fn(&ProgramStep) -> String,
) -> GeopResult<Vec<String>>
pub fn paste( &mut self, pasted: Self, index: usize, registry: &OperationRegistry, label: impl Fn(&ProgramStep) -> String, ) -> GeopResult<Vec<String>>
Inserts the steps of pasted at index, in order, with the state
that is theirs (see Program::excerpt): each under its own id
where no step has it yet, else under a fresh one — label naming a
step’s operation. The ids they got, in order. pasted is checked
against registry first (see Program::validate).
A step pasted under a fresh id is the step the steps pasted with it,
itself too, name by that id: every name of theirs that names a step
pasted, in their arguments and their state, is renamed with it
(rename_steps). A sketch and its extrusion pasted twice are two
extrusions, each of its own sketch; a part placed and mated, pasted,
is a second part, mated as itself.
Sourcepub fn validate_ids(&self) -> GeopResult<()>
pub fn validate_ids(&self) -> GeopResult<()>
Checks that every step id is a valid operation id
(validate_operation_id) and unique: every name a step creates is
built from its id.
Sourcepub fn validate(&self, registry: &OperationRegistry) -> GeopResult<()>
pub fn validate(&self, registry: &OperationRegistry) -> GeopResult<()>
Checks the program against the operations of registry, which it is
run in: its ids (see Program::validate_ids), and that every step
is of an operation there is, with arguments that operation reads.
An error names the step.