pub struct ProgressState<'a, F>where
F: ProgressCallback + ?Sized,{ /* private fields */ }Expand description
Helper wrapper for throttling progress callback frequency.
Some operations progress very quickly (e.g., processing thousands of items), and reporting progress on every item would overwhelm the callback and impact performance. This wrapper enforces a minimum time between updates.
§Example
use sqlitegraph::progress::{ProgressCallback, ProgressState, NoProgress};
use std::time::Duration;
let inner = NoProgress;
let mut progress = ProgressState::new(&inner, Duration::from_millis(100));
// Only reports if at least 100ms has passed since last report
progress.update(5, Some(10), "Processing")?;
progress.update(6, Some(10), "Processing")?; // May be skippedImplementations§
Source§impl<'a, F> ProgressState<'a, F>where
F: ProgressCallback + ?Sized,
impl<'a, F> ProgressState<'a, F>where
F: ProgressCallback + ?Sized,
Sourcepub fn new(callback: &'a F, interval: Duration) -> Self
pub fn new(callback: &'a F, interval: Duration) -> Self
Creates a new progress state wrapper.
§Parameters
callback: The underlying progress callback to wrapinterval: Minimum time between progress updates
§Example
use sqlitegraph::progress::{ProgressCallback, ProgressState, NoProgress};
use std::time::Duration;
let callback = NoProgress;
let progress = ProgressState::new(&callback, Duration::from_millis(100));Sourcepub fn update(&mut self, current: usize, total: Option<usize>, message: &str)
pub fn update(&mut self, current: usize, total: Option<usize>, message: &str)
Updates progress, but only if the minimum interval has elapsed.
§Parameters
current: Current step or item being processedtotal: Total number of steps (if known)message: Human-readable progress message
§Example
// Returns immediately if interval hasn't elapsed
progress.update(50, Some(100), "Processing");Sourcepub fn force_update(
&mut self,
current: usize,
total: Option<usize>,
message: &str,
)
pub fn force_update( &mut self, current: usize, total: Option<usize>, message: &str, )
Forces an immediate progress update, bypassing the throttling logic.
Use this for important milestones (e.g., completion) that should always be reported regardless of timing.
§Example
// Always report the final update, even if interval hasn't elapsed
progress.force_update(100, Some(100), "Complete");Sourcepub fn update_interval(&self) -> Duration
pub fn update_interval(&self) -> Duration
Returns the configured update interval.
§Example
let interval = progress.update_interval();
assert_eq!(interval, Duration::from_millis(100));Trait Implementations§
Auto Trait Implementations§
impl<'a, F> !Freeze for ProgressState<'a, F>
impl<'a, F> RefUnwindSafe for ProgressState<'a, F>where
F: RefUnwindSafe + ?Sized,
impl<'a, F> Send for ProgressState<'a, F>where
F: ?Sized,
impl<'a, F> Sync for ProgressState<'a, F>where
F: ?Sized,
impl<'a, F> Unpin for ProgressState<'a, F>where
F: ?Sized,
impl<'a, F> UnwindSafe for ProgressState<'a, F>where
F: RefUnwindSafe + ?Sized,
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
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