pub trait ProgressHandler: Send + Sync {
// Required method
fn on_progress(&self, event: &ProgressEvent);
}Expand description
Receives progress updates from long-running upload and download operations.
Register a handler by wrapping it in Progress and passing it to the
.progress(...) setter of any method builder that supports progress reporting.
See the module-level docs for the event model, ordering guarantees, and
the must-not-block / Send + Sync contract.
§Example
use std::sync::atomic::{AtomicU64, Ordering};
use hf_hub::progress::{ProgressEvent, ProgressHandler, UploadEvent};
struct ByteCounter {
bytes: AtomicU64,
}
impl ProgressHandler for ByteCounter {
fn on_progress(&self, event: &ProgressEvent) {
if let ProgressEvent::Upload(UploadEvent::Progress {
bytes_completed, ..
}) = event
{
self.bytes.store(*bytes_completed, Ordering::Relaxed);
}
}
}Required Methods§
Sourcefn on_progress(&self, event: &ProgressEvent)
fn on_progress(&self, event: &ProgressEvent)
Invoked by the library for each progress event. The event reference is
only valid for the duration of the call.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".