use crate::types::Version;
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
pub struct ConstVersion<const N: i16>;
impl<const N: i16> ConstVersion<N> {
pub const VALUE: Version = {
assert!(N >= 1 && N <= 40, "normal QR version must be in 1..=40");
Version::Normal(N)
};
pub const fn new() -> Self {
let _ = Self::VALUE;
Self
}
pub const fn version(self) -> Version {
Self::VALUE
}
}
pub trait StaticVersion: Copy {
const VERSION: Version;
}
impl<const N: i16> StaticVersion for ConstVersion<N> {
const VERSION: Version = ConstVersion::<N>::VALUE;
}
#[cfg(test)]
mod tests {
use super::{ConstVersion, StaticVersion};
use crate::types::Version;
#[test]
fn const_version_exposes_dynamic_normal_version() {
const V5: Version = ConstVersion::<5>::VALUE;
assert_eq!(V5, Version::Normal(5));
assert_eq!(ConstVersion::<5>::new().version(), Version::Normal(5));
assert_eq!(<ConstVersion<5> as StaticVersion>::VERSION, Version::Normal(5));
}
}