Skip to main content

Store

Struct Store 

Source
pub struct Store<'w> { /* private fields */ }
Expand description

File store for one project, rooted at one environment’s tree.

Implementations§

Source§

impl<'w> Store<'w>

Source

pub fn new(project: &'w Project, env: &str) -> Self

Source

pub fn project(&self) -> &Project

Source

pub fn env(&self) -> &str

Source

pub fn envs_of(project: &Project) -> Vec<String>

List the environments a project participates in: the sorted names of <project>/envs/* subdirectories. A project with no env dirs yet participates in none (scaffold/adopt/pull materializes them lazily).

Source

pub fn path_for(&self, r: &ResourceRef) -> PathBuf

Absolute path for a NEW resource file (used on create — the physical name becomes the filename). Existing resources may live at a different path when their file stem diverged from the physical name; use Store::locate to find those.

Source

pub fn locate(&self, r: &ResourceRef) -> Result<Option<PathBuf>, StoreError>

Find the file in this store whose physical name (name field, or the file stem when absent) equals r.name. Scans the kind directory — small dirs, correctness over micro-optimization.

Source

pub fn list(&self) -> Result<Vec<(ResourceRef, PathBuf)>, StoreError>

Scan this store’s environment tree for resource files, keyed by PHYSICAL name (the file’s name field, falling back to its stem).

A file with invalid JSON is a HARD error (deliberately): sync operations (push/pull/prune/ownership checks) build their world view from this listing, and silently skipping a broken file would let them act on a partial view — e.g. pruning a resource that still exists locally. Fail loud and name the file instead.

Source

pub fn read(&self, r: &ResourceRef) -> Result<Value, StoreError>

Read a resource file with sidecars inlined. Locates the file by physical name; when nothing matches, the error keeps the plain Io not-found shape callers expect (pointing at the stem-guessed path). It never falls through to reading a file whose physical name differs from r.name (a renamed resource occupying the stem).

Source

pub fn read_path(&self, path: &Path) -> Result<Value, StoreError>

Read any resource file (must belong to this project) with sidecars inlined.

Source

pub fn write(&self, r: &ResourceRef, value: &Value) -> Result<bool, StoreError>

Write a resource: normalize for disk, extract sidecars, write only if the semantic content changed. Returns true if the file was (re)written.

Updates the located file when one exists (by physical name). When none exists (create), the target stem is DISAMBIGUATED, never stolen: if <name>.json is already occupied by a renamed resource, the new file lands at <name>-2.json (then -3, …). This keeps sync operations (pull/adopt capture cloud reality mid-run) robust instead of failing, while locate keeps lookups correct regardless of stem.

Source

pub fn write_at( &self, stem: &str, kind: ResourceKind, value: &Value, ) -> Result<bool, StoreError>

Write a resource at an explicit STEM rather than its physical name — used by rigg promote when creating a resource in the target environment that has no counterpart there yet: the new file must land at the SOURCE environment’s stem (its logical/correlation id) so the two trees keep correlating by path, even when the resource’s physical name differs from that stem (a renamed resource in the source env).

Unlike Store::write (which locates-or-creates by physical name), this never disambiguates: if <stem>.json already exists and holds a DIFFERENT physical name than value, that’s a genuine collision (some other resource already occupies this stem) and it errors rather than overwriting or guessing a new path. When the existing file’s physical name matches, it behaves like write (update in place, same x-rigg-*/write-only carry-over and semantic-no-op short circuit).

Source

pub fn delete(&self, r: &ResourceRef) -> Result<(), StoreError>

Delete a resource file (and its default sidecars). Only ever removes the file locate resolves for this physical name — deleting a name that matches nothing is a no-op (never falls through to a stem-guessed path that could belong to a renamed resource).

Auto Trait Implementations§

§

impl<'w> Freeze for Store<'w>

§

impl<'w> RefUnwindSafe for Store<'w>

§

impl<'w> Send for Store<'w>

§

impl<'w> Sync for Store<'w>

§

impl<'w> Unpin for Store<'w>

§

impl<'w> UnsafeUnpin for Store<'w>

§

impl<'w> UnwindSafe for Store<'w>

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, 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.