use std::fmt::{self, Display, Formatter};
use std::io::{Read, Write, Result};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Version([u8; 4]);
impl Version {
pub const V3_2: Version = Version(*b"V3.2");
#[inline]
pub fn new(major: u8, minor: u8) -> Self {
Version([b'V', major + b'0', b'.', minor + b'0'])
}
#[inline]
pub fn major(&self) -> u8 { self.0[1] - b'0' }
#[inline]
pub fn minor(&self) -> u8 { self.0[3] - b'0' }
#[inline]
pub fn read<R: Read>(reader: &mut R) -> Result<Self> {
let mut version = Version([0u8; 4]);
reader.read(&mut version.0)?;
Ok(version)
}
#[inline]
pub fn write<W: Write>(&self, writer: &mut W) -> Result<()> {
writer.write_all(&self.0)
}
}
impl Display for Version {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{}.{}", self.major(), self.minor())
}
}