Skip to main content

SystemSidecar

Struct SystemSidecar 

Source
pub struct SystemSidecar<T> { /* private fields */ }
Expand description

Atomic JSON persistence for one _system/ document of type T.

T is the whole document — callers parameterize with the collection they store (SystemSidecar<Vec<Row>>). Persisting T rather than a hardwired Vec leaves room for a future versioned envelope without changing this IO layer.

Implementations§

Source§

impl<T> SystemSidecar<T>

Source

pub fn new(data_path: impl AsRef<Path>, file_name: &str) -> Self

Construct a sidecar rooted at <data_path>/_system/<file_name>.

file_name must match the on-disk name the subsystem has always used — changing it would orphan existing state across an upgrade.

Source

pub fn at_path(path: impl Into<PathBuf>) -> Self

Construct a sidecar at an exact path, bypassing the _system/ convention.

For callers that already own the full target path (e.g. an embedder that supplies it directly) and must keep that exact location for on-disk compatibility.

Source

pub fn path(&self) -> &Path

Borrow the resolved sidecar path (for diagnostics).

Source

pub fn load(&self) -> Result<T, SidecarIoError>

Load the persisted document, or T::default() if absent or empty.

A missing file and a zero-byte file both mean “nothing persisted yet” and yield the default — first-boot callers rely on this.

§Errors

Returns SidecarIoError::Read on IO failure or SidecarIoError::Decode when the file is present but not valid JSON.

Source

pub fn store(&self, value: &T) -> Result<(), SidecarIoError>
where T: Serialize,

Atomically replace the persisted document with value.

Writes a temp file, fsyncs it, renames it over the target, then fsyncs the parent directory so the rename itself is crash-durable.

§Errors

Returns SidecarIoError::Encode if serialization fails, SidecarIoError::CreateDir if the _system/ directory cannot be created, or SidecarIoError::Write on any write / fsync / rename failure.

Source

pub fn store_value<S>(&self, value: &S) -> Result<(), SidecarIoError>
where S: Serialize + ?Sized,

Atomically replace the persisted document with any value that serializes to the same JSON as T.

Identical to Self::store but accepts a borrowed view (e.g. a &[Row] for a SystemSidecar<Vec<Row>>) so callers that already own a slice can persist it without cloning into an owned T first. S must serialize to the same shape T deserializes from — the caller guarantees this.

§Errors

Same as Self::store.

Trait Implementations§

Source§

impl<T> Clone for SystemSidecar<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for SystemSidecar<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for SystemSidecar<T>

§

impl<T> RefUnwindSafe for SystemSidecar<T>

§

impl<T> Send for SystemSidecar<T>

§

impl<T> Sync for SystemSidecar<T>

§

impl<T> Unpin for SystemSidecar<T>

§

impl<T> UnsafeUnpin for SystemSidecar<T>

§

impl<T> UnwindSafe for SystemSidecar<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.