pub struct CheckpointManager {
pub directory: PathBuf,
pub base_name: String,
pub format: CheckpointFormat,
pub keep_n: usize,
pub interval: usize,
pub max_bytes: u64,
/* private fields */
}Expand description
Checkpoint manager for automatic saving
Fields§
§directory: PathBufDirectory for checkpoint files
base_name: StringBase filename for checkpoints
format: CheckpointFormatSerialization format
keep_n: usizeHow many checkpoints to keep
interval: usizeSave interval (generations)
max_bytes: u64Maximum checkpoint size accepted when loading (EV-48)
Implementations§
Source§impl CheckpointManager
impl CheckpointManager
Sourcepub fn new(directory: impl Into<PathBuf>, base_name: impl Into<String>) -> Self
pub fn new(directory: impl Into<PathBuf>, base_name: impl Into<String>) -> Self
Create a new checkpoint manager.
The manager is restart-safe (EV-46): it scans directory for existing
checkpoints named after base_name and continues the index after the
highest one found, so a fresh manager constructed after a crash never
overwrites or shadows pre-crash checkpoints.
Sourcepub fn with_format(self, format: CheckpointFormat) -> Self
pub fn with_format(self, format: CheckpointFormat) -> Self
Set the serialization format
Sourcepub fn with_max_bytes(self, max_bytes: u64) -> Self
pub fn with_max_bytes(self, max_bytes: u64) -> Self
Set the maximum checkpoint size accepted by load_latest (EV-48).
Sourcepub fn current_index(&self) -> usize
pub fn current_index(&self) -> usize
The index the next save will write to.
Exposed primarily so restart-resume behavior (EV-46) is observable/testable.
Sourcepub fn should_save(&self, generation: usize) -> bool
pub fn should_save(&self, generation: usize) -> bool
Check if a checkpoint should be saved at this generation
Sourcepub fn current_path(&self) -> PathBuf
pub fn current_path(&self) -> PathBuf
Get the path for the current checkpoint
Sourcepub fn save<G>(
&mut self,
checkpoint: &Checkpoint<G>,
) -> Result<(), CheckpointError>
pub fn save<G>( &mut self, checkpoint: &Checkpoint<G>, ) -> Result<(), CheckpointError>
Save a checkpoint and rotate old ones
Sourcepub fn load_latest<G>(&self) -> Result<Option<Checkpoint<G>>, CheckpointError>
pub fn load_latest<G>(&self) -> Result<Option<Checkpoint<G>>, CheckpointError>
Find and load the latest checkpoint
Auto Trait Implementations§
impl Freeze for CheckpointManager
impl RefUnwindSafe for CheckpointManager
impl Send for CheckpointManager
impl Sync for CheckpointManager
impl Unpin for CheckpointManager
impl UnsafeUnpin for CheckpointManager
impl UnwindSafe for CheckpointManager
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
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.