Skip to main content

hyphae_core/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Stable product identity and version values shared by Hyphae surfaces.
4
5/// Canonical product and executable name.
6pub const PRODUCT_NAME: &str = "hyphae";
7
8/// Current public HTTP API version.
9pub const API_VERSION: &str = "v1";
10
11/// Current on-disk format version.
12pub const DISK_FORMAT_VERSION: u16 = 1;
13
14/// Product version information that can be reported without opening a data directory.
15#[derive(Clone, Copy, Debug, Eq, PartialEq)]
16pub struct VersionInfo {
17    /// Product name.
18    pub product: &'static str,
19    /// Cargo package version for the running binary.
20    pub engine: &'static str,
21    /// Public HTTP API version.
22    pub api: &'static str,
23    /// On-disk format version.
24    pub disk_format: u16,
25}
26
27/// Returns the version information compiled into this build.
28pub const fn current_version() -> VersionInfo {
29    VersionInfo {
30        product: PRODUCT_NAME,
31        engine: env!("CARGO_PKG_VERSION"),
32        api: API_VERSION,
33        disk_format: DISK_FORMAT_VERSION,
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::{API_VERSION, DISK_FORMAT_VERSION, PRODUCT_NAME, current_version};
40
41    #[test]
42    fn current_version_matches_public_constants() {
43        let version = current_version();
44        assert_eq!(version.product, PRODUCT_NAME);
45        assert_eq!(version.api, API_VERSION);
46        assert_eq!(version.disk_format, DISK_FORMAT_VERSION);
47        assert!(!version.engine.is_empty());
48    }
49}