flow-abi 0.1.0-rc.5

The host boundary's value encoding: the binary encoding and the JSON form, the canonical form and its hash, JSON Schemas, Tool signatures, and the answers a Tool call passes.
Documentation
//! The data version (`abi.md`, `trace.md`, *The data version*), and bytes
//! written in one.

use std::fmt;

use crate::wire;
use crate::wire::Rest;

wire! {
    /// A data version: one version for the value encoding, the Tool protocol
    /// and the history format together, written `"major.minor"`.
    ///
    /// Minors only add, so a reader of one minor reads every earlier minor of
    /// the same major; a change of meaning takes a new major.
    #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
    pub struct DataVersion {
        /// What a change of meaning moves.
        pub major: u64,
        /// What an addition moves.
        pub minor: u64,
    }
}

wire! {
    /// Bytes written in a data version: the version, then what follows,
    /// which only a reader of that version reads.
    #[derive(Clone, PartialEq, Eq, Debug)]
    pub struct Versioned {
        /// The version the rest is written in.
        pub version: DataVersion,
        /// What follows it.
        pub rest: Rest,
    }
}

impl DataVersion {
    /// The version `text` writes as `"major.minor"`, each a number in its
    /// one decimal spelling: no sign, no leading zero, nothing else. `None`
    /// for any other text.
    pub fn parse(text: &str) -> Option<DataVersion> {
        let (major, minor) = text.split_once('.')?;
        let number = |part: &str| {
            part.parse::<u64>()
                .ok()
                .filter(|value| value.to_string() == part)
        };
        Some(DataVersion {
            major: number(major)?,
            minor: number(minor)?,
        })
    }

    /// Whether a reader of this version reads data written in `other`: the
    /// same major, and a minor no newer than this one's.
    pub fn reads(&self, other: &DataVersion) -> bool {
        self.major == other.major && other.minor <= self.minor
    }

    /// Whether a peer of this version and one of `other` speak the Tool
    /// process protocol to each other: the same major, whatever their
    /// minors (`abi.md`, *The Tool process protocol*).
    pub fn speaks_with(&self, other: &DataVersion) -> bool {
        self.major == other.major
    }
}

impl fmt::Display for DataVersion {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}.{}", self.major, self.minor)
    }
}

/// This implementation's data version. No data version is stable before the
/// first public release.
pub const DATA_VERSION: DataVersion = DataVersion { major: 6, minor: 0 };