pub struct Workflow { /* private fields */ }Expand description
In-memory workflow with journaled versioning for AIMX rules.
Maintains ordered rule rows plus identifier lookup, tracks changes as
Changes, and persists via versioned AIM/journal files.
Implementations§
Source§impl Workflow
impl Workflow
Sourcepub fn for_testing(locator: Arc<Reference>) -> Result<Self>
pub fn for_testing(locator: Arc<Reference>) -> Result<Self>
Creates a new empty workflow.
The workflow starts with:
- Empty rule storage
- Version 0.0
- Extract inference pattern
- Empty path and reference
- No changes pending
- Change tracking disabled
Sourcepub fn parse_for_tests(input: &str) -> Result<Self>
pub fn parse_for_tests(input: &str) -> Result<Self>
Creates a new workflow by parsing AIM content.
This constructor parses the provided AIM content and creates a workflow with the parsed rules. Change tracking is automatically enabled.
pub fn new_from(locator: Arc<Reference>, path: Arc<PathBuf>) -> Self
Sourcepub fn open(locator: Arc<Reference>) -> Result<Self>
pub fn open(locator: Arc<Reference>) -> Result<Self>
Creates a new workflow by loading from a global locator (Reference).
This constructor loads a workflow from the file system based on the provided locator. If the file doesn’t exist, an empty workflow is created with the locator set.
Sourcepub fn is_touched(&self) -> bool
pub fn is_touched(&self) -> bool
Checks if the workflow has unsaved changes.
§Returns
true if the workflow has changes that need to be saved, false otherwise.
Sourcepub fn set_partial_change(&mut self)
pub fn set_partial_change(&mut self)
Flags changes that only require a partial save.
This method escalates the change status from None to Partial.
If changes are already at Partial or Version, they remain unchanged.
Sourcepub fn set_version_change(&mut self)
pub fn set_version_change(&mut self)
Flags changes that require a version change on save.
This method sets the change status to Version, indicating that
structural changes have been made that require a new version.
Sourcepub fn clear_changes(&mut self)
pub fn clear_changes(&mut self)
Clears the changes flag.
This method is typically called after a successful save operation to reset the change tracking state.
Sourcepub fn first_version(&self) -> u32
pub fn first_version(&self) -> u32
Gets the first version number from the journal.
§Returns
The epoch of the first version, or 0 if no versions exist.
Sourcepub fn latest_version(&self) -> u32
pub fn latest_version(&self) -> u32
Gets the latest version number from the journal.
§Returns
The epoch of the latest version, or 0 if no versions exist.
Sourcepub fn load_version(&mut self, version: u32, partial: Option<u32>) -> Result<()>
pub fn load_version(&mut self, version: u32, partial: Option<u32>) -> Result<()>
Loads a specific version of an AIM file.
This method loads a particular version (and optionally a specific partial) from the AIM file. After loading, the workflow switches back to the latest version but flags that a version change is needed since the loaded version differs from the current one.
§Parameters
path- The path to the AIM fileversion- The epoch version to loadpartial- Optional partial version within the epoch
§Returns
Ok(()) if successful, or an error if the version cannot be loaded.
Sourcepub fn save(&mut self) -> Result<()>
pub fn save(&mut self) -> Result<()>
Saves the AIM structure to its associated file.
This function saves changes to the AIM file based on the type of changes made:
Changes::Version: Creates a new version with incremented epochChanges::Partial: Creates a partial update with incremented partial counterChanges::None: No changes to save, returns Ok(())
The function also updates the journal file with position information for fast lookup.
§Returns
Ok(()) if successful, or an error if the save operation fails.
pub fn save_all(&mut self) -> Result<()>
pub fn check_identifier_unique(&self, identifier: &str) -> Result<()>
pub fn add_node( &mut self, identifier: Arc<str>, node: Node, ) -> Result<Arc<Reference>>
pub fn copy_node(&mut self, from: &Node, to: Arc<str>) -> Result<()>
pub fn get_node(&self, identifier: &str) -> Result<Node>
pub fn rename_node(&mut self, from: &str, to: Arc<str>) -> Result<()>
pub fn delete_node(&mut self, identifier: &str) -> Result<()>
pub fn add_instance( &mut self, identifier: Arc<str>, source: Arc<Reference>, target: Arc<Reference>, ) -> Result<()>
Sourcepub fn append_or_update(&mut self, row: Row)
pub fn append_or_update(&mut self, row: Row)
Appends a row to the workflow or updates an existing rule.
If a rule with the same identifier already exists, it is updated. Otherwise, the rule is appended to the end of the workflow.
§Parameters
row- The rule to append or update
Sourcepub fn delete_rule(&mut self, identifier: &str) -> Row
pub fn delete_rule(&mut self, identifier: &str) -> Row
Sourcepub fn set_row(&mut self, index: usize, row: Row) -> Result<()>
pub fn set_row(&mut self, index: usize, row: Row) -> Result<()>
Sets a rule at a specific row index.
If a rule already exists at the specified index with a different identifier, this method will return an error. If the index is beyond the current size of the workflow, the rows vector will be expanded to accommodate it.
§Parameters
index- The zero-based row index where to place the rulerow- The rule to set, or None to create an empty row
§Returns
Ok(()) if successful, or an error if there’s a conflict with an existing rule
Sourcepub fn insert_row(&mut self, index: usize, row: Row) -> Result<()>
pub fn insert_row(&mut self, index: usize, row: Row) -> Result<()>
Inserts a rule at a specific row index.
This method inserts a rule at the specified index, shifting existing rules to higher indices. If the index is beyond the current size of the workflow, empty rows will be created as needed. If a rule with the same identifier already exists in the workflow, this method returns an error.
§Parameters
index- The zero-based row index where to insert the rulerow- The rule to insert, or None to create an empty row
§Returns
Ok(()) if successful, or an error if a rule with the same identifier already exists
Sourcepub fn reposition_row(&mut self, from: usize, to: usize) -> Result<()>
pub fn reposition_row(&mut self, from: usize, to: usize) -> Result<()>
Repositions a rule from one row index to another.
This method moves a rule from the from index to the to index,
shifting other rules as needed. If either index is beyond the current
size of the workflow, the rows vector will be expanded to accommodate them.
§Parameters
from- The current zero-based row index of the rule to moveto- The target zero-based row index where to place the rule
§Returns
Ok(()) if successful, or an error if the operation fails
pub fn replace_row(&mut self, index: usize, row: Row) -> Result<()>
Sourcepub fn clear_row(&mut self, index: usize) -> Row
pub fn clear_row(&mut self, index: usize) -> Row
Clears a row at a specific index, removing the rule if present.
This method removes the rule at the specified index but keeps the row structure intact. The row will become empty but still exist in the workflow. If the index is out of bounds, this method returns None.
§Parameters
index- The zero-based row index to clear
§Returns
Some(Rule) if a rule was present and removed, None if the row was already empty or index was out of bounds
Sourcepub fn remove_row(&mut self, index: usize) -> Row
pub fn remove_row(&mut self, index: usize) -> Row
Removes a row at a specific index, removing the rule and shrinking the workflow.
This method removes the rule at the specified index and removes the row entirely from the workflow, shifting subsequent rows to lower indices. If the index is out of bounds, this method returns None.
§Parameters
index- The zero-based row index to remove
§Returns
Some(Rule) if a rule was present and removed, None if the index was out of bounds
Sourcepub fn iter_with_rows(&self) -> impl Iterator<Item = (usize, &Row)>
pub fn iter_with_rows(&self) -> impl Iterator<Item = (usize, &Row)>
Create an iterator over the rules with their indices.
This iterator yields tuples of (index, &Option<Rule>), providing
both the position and content of each row including empty ones.
Sourcepub fn reindex(&mut self)
pub fn reindex(&mut self)
Rebuilds the lookup mapping index.
This helper function rebuilds the internal hash map that maps rule identifiers to their row indices. It’s called automatically after operations that change the position of rules within the workflow.
Sourcepub fn parse(&mut self, input: &str, partial: Option<u32>) -> Result<()>
pub fn parse(&mut self, input: &str, partial: Option<u32>) -> Result<()>
Parses AIM content and populates the workflow.
This method parses AIM format content and creates rules based on the parsed data. It can optionally parse only up to a specific partial version. The method clears the current workflow contents before parsing.
§Special tokens and their meanings
[..]HEADER: Used to signify a version header.:PARTIAL: Used inside a workflow header to signify a minor version number.@DATETIME: Used inside a workflow header to signify the snapshot date and time.#COMMENT: Used to signify a comment.$CONSTANT: Used inside rule a definitions to signify a constant variable.(..)Delimits expression parenthesis{..}Delimits and expression collection"|'Delimits strings^,!,&,%,*Potentially available
§Parameters
input- The AIM content to parsepartial- Optional partial version to parse up to
§Returns
Ok(()) if parsing was successful, or an error if parsing failed
pub fn print(&self, writer: &mut Writer)
Sourcepub fn to_formula(&self) -> String
pub fn to_formula(&self) -> String
Return the formula-string representation (round-trippable by the parser).
Trait Implementations§
Source§impl WorkflowLike for Workflow
impl WorkflowLike for Workflow
Source§fn locator(&self) -> Arc<Reference>
fn locator(&self) -> Arc<Reference>
Source§fn path(&self) -> Arc<PathBuf>
fn path(&self) -> Arc<PathBuf>
fn date(&self) -> DateTime
Source§fn minor_version(&self) -> u32
fn minor_version(&self) -> u32
Source§fn get_index(&self, identifier: &str) -> Option<usize>
fn get_index(&self, identifier: &str) -> Option<usize>
Source§fn has_rule(&self, index: usize) -> bool
fn has_rule(&self, index: usize) -> bool
Source§fn contains(&self, identifier: &str) -> bool
fn contains(&self, identifier: &str) -> bool
Source§fn get_rule(&self, identifier: &str) -> Option<Arc<Rule>>
fn get_rule(&self, identifier: &str) -> Option<Arc<Rule>>
Source§fn rule_count(&self) -> usize
fn rule_count(&self) -> usize
Source§fn iter_rows<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Row> + 'a>
fn iter_rows<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Row> + 'a>
Source§impl WriterLike for Workflow
impl WriterLike for Workflow
Source§fn to_stringized(&self) -> String
fn to_stringized(&self) -> String
Source§fn to_sanitized(&self) -> String
fn to_sanitized(&self) -> String
Source§fn to_expressionized(&self) -> String
fn to_expressionized(&self) -> String
Auto Trait Implementations§
impl Freeze for Workflow
impl RefUnwindSafe for Workflow
impl Send for Workflow
impl Sync for Workflow
impl Unpin for Workflow
impl UnwindSafe for Workflow
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> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.