Skip to main content

Program

Struct Program 

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

Implementations§

Source§

impl Program

Source

pub fn new() -> Self

A program of no steps and no state.

Source

pub fn from_steps(steps: Vec<ProgramStep>) -> Self

The program of steps, with no state.

Source

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.

Source

pub fn to_json(&self) -> GeopResult<String>

Source

pub fn step(&self, id: &str) -> GeopResult<&ProgramStep>

The step id.

Source

pub fn step_mut(&mut self, id: &str) -> GeopResult<&mut ProgramStep>

Source

pub fn index_of(&self, id: &str) -> GeopResult<usize>

The position of the step id.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Program

Source§

fn clone(&self) -> Program

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Program

Source§

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

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

impl Default for Program

Source§

fn default() -> Program

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Program

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Program

Source§

fn eq(&self, other: &Program) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Program

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Program

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.