flow-lang-value 0.1.0

The Flow runtime value model: data values, their equality, order and text, and the operations std's built-in types declare.
Documentation
//! The two ways an operation in this crate can decline.

use std::fmt;

/// Why an arithmetic operation produced no value.
///
/// `data.md` makes a zero divisor the only operation on its types that faults.
/// The evaluator turns either of these into a fault; neither is a value a
/// program can observe.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Fault {
    /// `int.div`, `%` or `/` was given a zero divisor.
    DivisionByZero,
    /// The exact result exists but its scale cannot be represented: a
    /// `Decimal` whose power of ten falls outside a signed 64-bit exponent.
    ///
    /// This is a host limit in `errors.md`'s sense, of a kind with running out
    /// of memory for a large `Int`, not a rule about the number.
    Limit,
}

impl fmt::Display for Fault {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(match self {
            Fault::DivisionByZero => "division by zero",
            Fault::Limit => "the result's scale exceeds what this host represents",
        })
    }
}

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

/// Why equality, ordering or text was refused.
///
/// `types.md` makes each of these a compile error on a type that is not data,
/// so a checked program never reaches either case. They exist so that a defect
/// upstream surfaces as a typed refusal rather than as an answer invented here.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum DataError {
    /// A function, a task, a host token or another evaluator-owned value was
    /// reached: none of them has equality, an order or a text form.
    NotData,
    /// The two values are not of one type.
    Mismatch,
}

impl fmt::Display for DataError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(match self {
            DataError::NotData => "the value is not data",
            DataError::Mismatch => "the values are not of one type",
        })
    }
}

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