Skip to main content

aam_core/commands/
mod.rs

1//! Command infrastructure for AAML directives.
2//!
3//! Each directive (`@import`, `@derive`, `@schema`, `@type`) is implemented as
4//! a struct that implements the [`Command`] trait and is registered in
5//! [`AAML::register_default_commands`](AAML).
6
7use crate::aaml::AAML;
8use crate::error::AamlError;
9
10pub mod derive;
11pub mod import;
12pub mod schema;
13pub mod typecm;
14
15/// Trait implemented by every AAML directive handler.
16///
17/// Commands are registered by name and invoked automatically when `@<name> <args>`
18/// is encountered during parsing.
19pub trait Command: Send + Sync {
20    /// The directive name without the leading `@` (e.g. `"import"`, `"schema"`).
21    fn name(&self) -> &str;
22
23    /// Executes the directive with the given argument string.
24    ///
25    /// `args` contains everything after the directive name on the same line,
26    /// with leading whitespace preserved.
27    ///
28    /// # Errors
29    ///
30    /// Returns an error if the directive is malformed, references are invalid,
31    /// or execution would violate schema constraints or circular dependency rules.
32    fn execute(&self, aaml: &mut AAML, args: &str) -> Result<(), AamlError>;
33}