pub struct StatePersistence;Expand description
Provides utility methods for loading and saving AppState from/to disk.
Implementations§
Source§impl StatePersistence
impl StatePersistence
Sourcepub fn get_state_path(config: &AppConfig) -> PathType
pub fn get_state_path(config: &AppConfig) -> PathType
Derives the default save path for the application state using /opt/artisan/tmp/.<app_name>.state.
§Example
let config = AppConfig::dummy();
let path = StatePersistence::get_state_path(&config);
println!("State file path: {:?}", path);Sourcepub async fn save_state(
state: &AppState,
path: &PathType,
) -> Result<(), Box<dyn Error>>
pub async fn save_state( state: &AppState, path: &PathType, ) -> Result<(), Box<dyn Error>>
Saves the provided AppState to the specified path.
The data is serialized to TOML, then encrypted with simple_encrypt.
§Errors
- Returns an
Errif serialization, encryption, or writing to the file fails.
Sourcepub async fn load_state(path: &PathType) -> Result<AppState, Box<dyn Error>>
pub async fn load_state(path: &PathType) -> Result<AppState, Box<dyn Error>>
Loads an AppState from the specified path.
Reads the file, then decrypts it with simple_decrypt, and finally deserializes from TOML.
§Errors
- Returns an
Errif decryption or TOML deserialization fails, or if the file is unreadable.
Auto Trait Implementations§
impl Freeze for StatePersistence
impl RefUnwindSafe for StatePersistence
impl Send for StatePersistence
impl Sync for StatePersistence
impl Unpin for StatePersistence
impl UnsafeUnpin for StatePersistence
impl UnwindSafe for StatePersistence
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
Converts
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> ⓘ
Converts
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