imping_ir/version.rs
1//! The IR file's format version.
2
3use serde::{Deserialize, Serialize};
4
5/// The major format version this crate reads and writes.
6///
7/// Other majors are rejected; see [`FormatVersion`]. Independent of the
8/// crate's own version.
9pub const SUPPORTED_MAJOR: u16 = 1;
10
11/// The minor format version this crate writes.
12pub const CURRENT_MINOR: u16 = 2;
13
14/// The format version of an IR file.
15///
16/// Breaking changes bump the major, backward-compatible additions the minor.
17/// Readers accept any minor of [`SUPPORTED_MAJOR`] and ignore fields they
18/// don't know.
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
20#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
21pub struct FormatVersion {
22 /// The major version. Incompatible changes increment it.
23 pub major: u16,
24 /// The minor version. Backward-compatible additions increment it.
25 pub minor: u16,
26}
27
28impl FormatVersion {
29 /// The version this crate writes: [`SUPPORTED_MAJOR`].[`CURRENT_MINOR`].
30 pub const CURRENT: FormatVersion = FormatVersion {
31 major: SUPPORTED_MAJOR,
32 minor: CURRENT_MINOR,
33 };
34
35 /// Returns whether this crate can read a file of this version, i.e. whether
36 /// its major is [`SUPPORTED_MAJOR`].
37 pub fn is_supported(&self) -> bool {
38 self.major == SUPPORTED_MAJOR
39 }
40}