pub struct StateFile { /* private fields */ }Expand description
Atomic JSON persistence for daemon state.
Implementations§
Source§impl StateFile
impl StateFile
pub fn new(data_dir: &Path) -> Self
Sourcepub fn save(&self, state: &DaemonState) -> Result<()>
pub fn save(&self, state: &DaemonState) -> Result<()>
Persist state using a same-directory temporary file and rename.
§Errors
Returns an error when the directory or state file cannot be written.
Sourcepub fn load(&self) -> Result<Option<DaemonState>>
pub fn load(&self) -> Result<Option<DaemonState>>
Load the state, returning None when no state file exists.
§Errors
Returns an error when the state file cannot be read or contains invalid JSON.
Sourcepub fn save_status(&self, report: &DaemonStatusReport) -> Result<()>
pub fn save_status(&self, report: &DaemonStatusReport) -> Result<()>
Persist the current daemon activity report atomically.
§Errors
Returns an error when the report cannot be serialized or written.
Sourcepub fn load_status(&self) -> Result<Option<DaemonStatusReport>>
pub fn load_status(&self) -> Result<Option<DaemonStatusReport>>
Load the last daemon activity report.
§Errors
Returns an error when the report cannot be read or contains invalid JSON.
pub fn exists(&self) -> bool
Sourcepub fn remove_status(&self) -> Result<()>
pub fn remove_status(&self) -> Result<()>
Remove the status report if it exists.
§Errors
Returns an error when the status report cannot be removed.
Sourcepub fn is_running(&self) -> Result<bool>
pub fn is_running(&self) -> Result<bool>
Return the initial PID liveness hint stored in the state file.
A positive result does not prove that the process is the syncweb daemon; callers should verify it through IPC.
§Errors
Returns an error when the state file cannot be read or decoded.
pub fn path(&self) -> &Path
pub fn status_path(&self) -> PathBuf
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StateFile
impl RefUnwindSafe for StateFile
impl Send for StateFile
impl Sync for StateFile
impl Unpin for StateFile
impl UnsafeUnpin for StateFile
impl UnwindSafe for StateFile
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more