providers-kit 0.0.2

Portable enum-dispatch Kit over multiple model provider APIs.
Documentation
//! Provider health observations.
//!
//! [`HealthStatus`] reports successful probe latency. A successful probe does not
//! establish support or success for another model, file, batch, or session call.
//! Shared shutdown belongs to [`crate::ProviderBackend::shutdown`].

use std::future::Future;
use std::time::{Duration, Instant};

use serde::{Deserialize, Serialize};

use crate::KitError;

/// Successful provider health-probe result.
///
/// # Examples
///
/// ```
/// let health = providers_kit::runtime::HealthStatus { latency: std::time::Duration::from_millis(12) };
/// assert_eq!(health.latency.as_millis(), 12);
/// ```
///
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct HealthStatus {
    /// End-to-end probe latency.
    pub latency: Duration,
}

impl HealthStatus {
    pub(crate) async fn from_probe<T, F>(probe: F) -> Result<Self, KitError>
    where
        F: Future<Output = Result<T, KitError>>,
    {
        let start = Instant::now();
        probe.await?;
        Ok(Self {
            latency: start.elapsed(),
        })
    }
}