pub struct SamodLoader { /* private fields */ }Expand description
A state machine for loading a samod repository.
SamodLoader handles the initialization phase of a samod repository,
coordinating between the user and the driver to load or generate the storage ID
and perform any other setup operations required before the repository can be used.
§Usage
use samod_core::{PeerId, SamodLoader, LoaderState, UnixTimestamp, io::{StorageResult, IoResult}};
use rand::SeedableRng;
let mut rng = rand::rngs::StdRng::from_rng(&mut rand::rng());
let mut loader = SamodLoader::new(PeerId::from("test"));
loop {
match loader.step(&mut rng, UnixTimestamp::now()) {
LoaderState::NeedIo(tasks) => {
// Execute IO tasks and provide results
for task in tasks {
// ... execute task ...
loader.provide_io_result(result);
}
}
LoaderState::Loaded(samod) => {
// Repository is loaded and ready to use
break;
}
}
}Implementations§
Source§impl SamodLoader
impl SamodLoader
Sourcepub fn step<R: Rng>(&mut self, rng: &mut R, _now: UnixTimestamp) -> LoaderState
pub fn step<R: Rng>(&mut self, rng: &mut R, _now: UnixTimestamp) -> LoaderState
Advances the loader state machine.
This method should be called repeatedly until LoaderState::Loaded is returned.
When LoaderState::NeedIo is returned, the caller must execute the provided
IO tasks and call provide_io_result for each one before calling step again.
§Arguments
now- The current timestamp
§Returns
The current state of the loader.
Sourcepub fn provide_io_result(&mut self, result: IoResult<StorageResult>)
pub fn provide_io_result(&mut self, result: IoResult<StorageResult>)
Provides the result of an IO operation.
This method should be called for each IO task that was returned by step.
The loader passes the result directly to the driver for processing.
§Arguments
result- The result of executing an IO task
Auto Trait Implementations§
impl Freeze for SamodLoader
impl RefUnwindSafe for SamodLoader
impl Send for SamodLoader
impl Sync for SamodLoader
impl Unpin for SamodLoader
impl UnwindSafe for SamodLoader
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> 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