synapse-rs 1.1.0

A standardized metric system (Vortex, Radiance, Axon) to evaluate real-world network quality beyond simple speed tests.
Documentation
//! Errors returned when network metrics cannot be computed.

use std::fmt;

/// Errors that can occur while calculating Synapse metrics.
#[derive(Debug, Clone, PartialEq)]
pub enum SynapseError {
    /// One or more required fields were not provided.
    MissingField(&'static str),
    /// A numeric field was NaN, infinite, or outside its valid domain.
    InvalidValue {
        /// Name of the invalid field.
        field: &'static str,
        /// Why the value was rejected.
        reason: &'static str,
    },
}

impl fmt::Display for SynapseError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::MissingField(field) => write!(f, "missing required field: {field}"),
            Self::InvalidValue { field, reason } => {
                write!(f, "invalid value for {field}: {reason}")
            }
        }
    }
}

impl std::error::Error for SynapseError {}

/// Convenient alias for Synapse calculation results.
pub type Result<T> = std::result::Result<T, SynapseError>;