use core::fmt;
use crate::sys;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TelemetryApiVersion(u32);
impl TelemetryApiVersion {
pub const V1_00: Self = Self(sys::SCS_TELEMETRY_VERSION_1_00);
pub const V1_01: Self = Self(sys::SCS_TELEMETRY_VERSION_1_01);
pub const CURRENT: Self = Self(sys::SCS_TELEMETRY_VERSION_CURRENT);
#[must_use]
pub const fn new(major: u32, minor: u32) -> Self {
Self(sys::make_version(major, minor))
}
#[must_use]
pub const fn from_raw(raw: u32) -> Self {
Self(raw)
}
#[must_use]
pub const fn raw(self) -> u32 {
self.0
}
#[must_use]
pub const fn major(self) -> u32 {
sys::version_major(self.0)
}
#[must_use]
pub const fn minor(self) -> u32 {
sys::version_minor(self.0)
}
}
impl fmt::Display for TelemetryApiVersion {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "{}.{}", self.major(), self.minor())
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct InputApiVersion(u32);
impl InputApiVersion {
pub const V1_00: Self = Self(sys::SCS_INPUT_VERSION_1_00);
pub const CURRENT: Self = Self(sys::SCS_INPUT_VERSION_CURRENT);
#[must_use]
pub const fn new(major: u32, minor: u32) -> Self {
Self(sys::make_version(major, minor))
}
#[must_use]
pub const fn from_raw(raw: u32) -> Self {
Self(raw)
}
#[must_use]
pub const fn raw(self) -> u32 {
self.0
}
#[must_use]
pub const fn major(self) -> u32 {
sys::version_major(self.0)
}
#[must_use]
pub const fn minor(self) -> u32 {
sys::version_minor(self.0)
}
}
impl fmt::Display for InputApiVersion {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "{}.{}", self.major(), self.minor())
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct InputGameVersion(u32);
impl InputGameVersion {
#[must_use]
pub const fn new(major: u32, minor: u32) -> Self {
Self(sys::make_version(major, minor))
}
#[must_use]
pub const fn from_raw(raw: u32) -> Self {
Self(raw)
}
#[must_use]
pub const fn raw(self) -> u32 {
self.0
}
#[must_use]
pub const fn major(self) -> u32 {
sys::version_major(self.0)
}
#[must_use]
pub const fn minor(self) -> u32 {
sys::version_minor(self.0)
}
}
impl fmt::Display for InputGameVersion {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "{}.{}", self.major(), self.minor())
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct GameSchemaVersion(u32);
impl GameSchemaVersion {
#[must_use]
pub const fn new(major: u32, minor: u32) -> Self {
Self(sys::make_version(major, minor))
}
#[must_use]
pub const fn from_raw(raw: u32) -> Self {
Self(raw)
}
#[must_use]
pub const fn raw(self) -> u32 {
self.0
}
#[must_use]
pub const fn major(self) -> u32 {
sys::version_major(self.0)
}
#[must_use]
pub const fn minor(self) -> u32 {
sys::version_minor(self.0)
}
}
impl fmt::Display for GameSchemaVersion {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "{}.{}", self.major(), self.minor())
}
}
#[cfg(test)]
mod tests {
extern crate std;
use super::*;
use std::string::ToString;
#[test]
fn telemetry_api_version_preserves_unknown_values_for_negotiation() {
let future = TelemetryApiVersion::new(2, 7);
assert_eq!(future.major(), 2);
assert_eq!(future.minor(), 7);
assert_eq!(TelemetryApiVersion::from_raw(future.raw()), future);
assert_eq!(future.to_string(), "2.7");
}
#[test]
fn game_schema_version_is_not_interchangeable_with_api_version() {
let schema = GameSchemaVersion::new(1, 19);
assert_eq!(schema.major(), 1);
assert_eq!(schema.minor(), 19);
assert_eq!(GameSchemaVersion::from_raw(schema.raw()), schema);
assert_eq!(schema.to_string(), "1.19");
}
#[test]
fn input_versions_are_independent_from_telemetry_versions() {
assert_eq!(InputApiVersion::CURRENT, InputApiVersion::V1_00);
assert_eq!(InputApiVersion::V1_00.raw(), sys::make_version(1, 0));
assert_eq!(InputGameVersion::new(1, 0).to_string(), "1.0");
}
}