Skip to main content

Workspace

Struct Workspace 

Source
pub struct Workspace { /* private fields */ }
Expand description

Editable view of an apimock workspace.

§Internal layout

The Workspace holds the loaded TOML model (as a Config) plus two index maps:

  • id_to_address: NodeId → where the node lives in config.
  • address_to_id: reverse — used when rebuilding snapshots.

On every apply() that could move nodes around (Add / Remove / Move), these tables are partially rebuilt. Reloading the config discards them and re-seeds with fresh IDs.

Implementations§

Source§

impl Workspace

Source

pub fn load(root: PathBuf) -> Result<Self, WorkspaceError>

Load a workspace rooted at the given apimock.toml-like path.

Accepts either a direct path to the config file or the directory containing one; a missing file-path is searched for as apimock.toml inside root. Mirrors the CLI’s existing resolution rules.

Source

pub fn snapshot(&self) -> WorkspaceSnapshot

Build a snapshot for GUI rendering.

§Allocation cost

A snapshot fully owns its data (no borrows into the workspace) so the GUI can serialise / send / store it without lifetime gymnastics. This is O(total editable nodes) allocation per call; the GUI should call it once per edit, not once per render frame.

Source

pub fn apply(&mut self, cmd: EditCommand) -> Result<ApplyResult, ApplyError>

Apply one edit command, mutating the in-memory workspace.

§Shape of the implementation

Each EditCommand variant maps to a small helper method. The helpers return Result<Vec<NodeId>, ApplyError>; apply wraps the ok-path in an ApplyResult with the right requires_reload flag and reruns validation so the result carries up-to-date diagnostics.

§ID stability on structural changes

Commands that change positional layout (Remove / Delete / Move / Add) touch self.ids carefully so NodeIds that refer to the same logical node survive the operation. For example, after RemoveRuleSet { id } at index i, rule sets at positions i+1.. shift down by one: the code below explicitly migrates their IDs so a GUI that selected rule-set #3 before the edit still has the same ID pointing at what is now rule-set #2.

Source

pub fn validate(&self) -> ValidationReport

Validate the workspace and return a GUI-ready report.

Uses the same per-node checks snapshot() does so the numbers line up: a node rendered with a red underline in the snapshot will appear in report.diagnostics with the same message.

Source

pub fn save(&mut self) -> Result<SaveResult, SaveError>

Save the workspace back to disk. Step 4 will implement this.

Source

pub fn config(&self) -> &Config

Access the underlying Config. Intended for embedders that need to build a running Server from the same workspace. Edit via apply() instead of touching Config directly — changes made through this reference are invisible to the ID index.

Source

pub fn root_path(&self) -> &Path

Access the root path. Primarily for diagnostics.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more