Skip to main content

ProgressCallback

Trait ProgressCallback 

Source
pub trait ProgressCallback: Send + Sync {
    // Required methods
    fn on_progress(&self, current: usize, total: Option<usize>, message: &str);
    fn on_complete(&self);
    fn on_error(&self, error: &dyn Error);
}
Expand description

Callback trait for progress reporting on long-running operations.

This trait allows algorithms to report progress updates during execution, enabling user feedback and LLM visibility into operation status.

§Thread Safety

All methods are thread-safe (require Send + Sync), allowing progress callbacks to be shared across threads if needed.

§Example

use sqlitegraph::progress::ProgressCallback;

struct MyCallback {
    // Your fields here
}

impl ProgressCallback for MyCallback {
    fn on_progress(&self, current: usize, total: Option<usize>, message: &str) {
        // Handle progress update
    }

    fn on_complete(&self) {
        // Handle completion
    }

    fn on_error(&self, error: &dyn std::error::Error) {
        // Handle error
    }
}

Required Methods§

Source

fn on_progress(&self, current: usize, total: Option<usize>, message: &str)

Called when progress is made.

§Parameters
  • current: Current step or item being processed
  • total: Total number of steps (if known), None for indeterminate operations
  • message: Human-readable progress message
§Example
fn on_progress(&self, current: usize, total: Option<usize>, message: &str) {
    match total {
        Some(total) => println!("{}: {}/{}", message, current, total),
        None => println!("{}: {}", message, current),
    }
}
Source

fn on_complete(&self)

Called when the operation completes successfully.

This is called exactly once if no errors occur.

Source

fn on_error(&self, error: &dyn Error)

Called when the operation encounters an error.

§Parameters
  • error: The error that caused the operation to fail

This is called exactly once if an error occurs, and on_complete will not be called.

Implementors§