pub struct Program {
pub steps: Vec<Step>,
}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_core_part), so a program means the same thing every
time it is run — including after a round trip through JSON.
Fields§
§steps: Vec<Step>Implementations§
Source§impl Program
impl Program
pub fn new() -> Self
Sourcepub fn push(
&mut self,
id: impl Into<String>,
operation: impl Into<PartOperation>,
)
pub fn push( &mut self, id: impl Into<String>, operation: impl Into<PartOperation>, )
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: &PartOperation) -> String
pub fn fresh_id(&self, operation: &PartOperation) -> 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 update(&mut self, edit: ProgramEdit) -> GeopResult<Option<String>>
pub fn update(&mut self, edit: ProgramEdit) -> GeopResult<Option<String>>
Applies edit, returning the id of the step it inserted, changed or
moved (None for a removal or a replacement). An edit that would
leave the program invalid — an unknown step, a position past the end,
a duplicate or malformed id — is rejected and changes nothing.
This only changes the recipe; whether the steps still build is for
running it to say (see ProgramRunner).
Sourcepub fn apply<S: Scalar>(&self, part: Part<S>) -> GeopResult<Part<S>>
pub fn apply<S: Scalar>(&self, part: Part<S>) -> GeopResult<Part<S>>
Runs every step in order, starting from part (typically
Part::new), and returns the part the whole program builds — or
the first error any step raises, at which point the steps after it
never run.
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.
pub fn from_json(json: &str) -> GeopResult<Self>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Program
impl<'de> Deserialize<'de> for Program
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Program
Auto Trait Implementations§
impl Freeze for Program
impl RefUnwindSafe for Program
impl Send for Program
impl Sync for Program
impl Unpin for Program
impl UnsafeUnpin for Program
impl UnwindSafe for Program
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
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<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 more