use std::sync::Arc;
pub trait OpenProgressSink: Send + Sync {
fn report(&self, progress: OpenProgress);
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum OpenPhase {
Inspecting,
Migrating,
Validating,
Opening,
Complete,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum OpenScope {
Local,
Authority,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct OpenProgress {
pub scope: OpenScope,
pub phase: OpenPhase,
pub from_format: Option<u32>,
pub to_format: u32,
pub completed: Option<u64>,
pub total: Option<u64>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct OpenMigrationReport {
pub from_format: u32,
pub to_format: u32,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct OpenMigration {
pub scope: OpenScope,
pub from_format: u32,
pub to_format: u32,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OpenReport {
pub migrations: Vec<OpenMigration>,
pub format: u32,
pub initialized: bool,
pub migration: Option<OpenMigrationReport>,
}
pub(crate) fn emit_open_progress(
sink: Option<&Arc<dyn OpenProgressSink>>,
progress: OpenProgress,
) {
let Some(sink) = sink else { return };
let sink = Arc::clone(sink);
let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| sink.report(progress)));
}