pub struct Persistence { /* private fields */ }Expand description
Handles disk I/O for the MemStore.
Persistence uses an atomic “write-then-rename” strategy to ensure data integrity.
Each persona is stored in its own .json file.
Implementations§
Source§impl Persistence
impl Persistence
Sourcepub fn new<P: AsRef<Path>>(dir: P) -> Result<Self>
pub fn new<P: AsRef<Path>>(dir: P) -> Result<Self>
Initializes a new Persistence handler in the specified directory.
If the directory does not exist, it will be created.
Sourcepub fn save_persona(
&self,
persona_id: &str,
data: &HashMap<String, HashMap<String, Value>>,
) -> Result<()>
pub fn save_persona( &self, persona_id: &str, data: &HashMap<String, HashMap<String, Value>>, ) -> Result<()>
Writes a single persona’s data to a JSON file atomically.
This method writes to a temporary file first and then renames it to the final destination, preventing file corruption during power failures.
Auto Trait Implementations§
impl Freeze for Persistence
impl RefUnwindSafe for Persistence
impl Send for Persistence
impl Sync for Persistence
impl Unpin for Persistence
impl UnwindSafe for Persistence
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