pub struct Instructions {
pub schema: u32,
pub target: Target,
pub template: Template,
pub front: FrontMatter,
pub steps: Vec<Step>,
pub id_counter: u64,
pub retarget: Option<Retarget>,
}Fields§
§schema: u32§target: TargetThe assembly revision these instructions describe. Authoritative: the server derives what the instructions reference from this field alone.
template: Template§front: FrontMatter§steps: Vec<Step>The top-level steps, in order; each may hold children (Step::steps).
id_counter: u64§retarget: Option<Retarget>A re-target waiting for the author’s approval. Release is refused while it is set.
Implementations§
Source§impl Instructions
impl Instructions
Sourcepub fn from_value(value: &Value) -> Result<Self, String>
pub fn from_value(value: &Value) -> Result<Self, String>
Read the block from its JSON, validated. A schema-1 block (chapters of steps) reads as the tree: the root chapter’s steps at the top, a sub-assembly’s chapter as the children of the step that places it, and is schema 2 from then on (written back on the next edit).
Sourcepub fn coalesce_adds(&mut self)
pub fn coalesce_adds(&mut self)
Every step’s adds as one row per part (Step::coalesce_adds).
Sourcepub fn from_document(document: &Value) -> Result<Option<Self>, String>
pub fn from_document(document: &Value) -> Result<Option<Self>, String>
Read the block out of a whole document, if it has one.
pub fn to_value(&self) -> Value
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
The structural rules: a known schema, a template the layout can draw, unique step and field ids over the whole tree, well-formed fields, and no occurrence added twice.
Sourcepub fn next_id(&mut self, prefix: &str) -> String
pub fn next_id(&mut self, prefix: &str) -> String
A fresh id with prefix (MS step, MK callout, MF field; MC was
a chapter).
pub fn step_count(&self) -> usize
Sourcepub fn steps(&self) -> impl Iterator<Item = (usize, &Step)>
pub fn steps(&self) -> impl Iterator<Item = (usize, &Step)>
Every step in reading order (a step’s children, depth first, before the step itself) with its depth (0 at the top).
pub fn step(&self, step_id: &str) -> Option<&Step>
pub fn step_mut(&mut self, step_id: &str) -> Option<&mut Step>
Sourcepub fn siblings(&self, step_id: &str) -> Option<(&[Step], usize)>
pub fn siblings(&self, step_id: &str) -> Option<(&[Step], usize)>
The list the step sits in (its siblings, itself included) and its index there.
pub fn siblings_mut(&mut self, step_id: &str) -> Option<(&mut Vec<Step>, usize)>
Sourcepub fn parent_id(&self, step_id: &str) -> Option<Option<&str>>
pub fn parent_id(&self, step_id: &str) -> Option<Option<&str>>
The parent step’s id: Some(None) at the top level, None for an
unknown step.
Sourcepub fn group_steps_mut(&mut self, occurrence: &str) -> Option<&mut Vec<Step>>
pub fn group_steps_mut(&mut self, occurrence: &str) -> Option<&mut Vec<Step>>
The steps that build one assembly: the top level for "", else the
children of the step that places the sub-assembly at occurrence.
Sourcepub fn step_number(&self, step_id: &str) -> Option<usize>
pub fn step_number(&self, step_id: &str) -> Option<usize>
The step number a reader sees (1-based, in reading order).
Sourcepub fn tools_list(&self) -> Vec<(ToolUse, Vec<String>)>
pub fn tools_list(&self) -> Vec<(ToolUse, Vec<String>)>
Distinct tools in first-use order, with the step ids that use each.
Sourcepub fn parts_list(&self) -> Vec<PartsRow>
pub fn parts_list(&self) -> Vec<PartsRow>
The parts list: one row per part (and per sub-assembly), with its find number and the quantity added over every step, in first-add order.