hdf5_pure/libver.rs
1//! Library-version bounds — the [`H5F_libver_t`] concept.
2//!
3//! Every HDF5 file is encoded with a set of *format versions* (superblock,
4//! object headers, message encodings). A reader needs a library new enough to
5//! understand those versions, and the HDF5 C API lets a writer bound which
6//! versions a new file may use via `H5Pset_libver_bounds`. [`LibVer`] names the
7//! release boundaries at which the on-disk format changed, so callers of this
8//! crate can ask which format an existing file requires
9//! ([`crate::File::libver_bound`]) or constrain what a new file may emit
10//! ([`crate::FileBuilder::with_libver_bounds`]).
11//!
12//! [`H5F_libver_t`]: https://portal.hdfgroup.org/documentation/hdf5/latest/group___f_a_p_l.html
13
14/// A library-version boundary, mirroring HDF5's `H5F_libver_t`.
15///
16/// Variants are ordered oldest to newest; a later variant understands strictly
17/// more of the format than an earlier one. `LibVer` derives `Ord` on that
18/// ordering, so bounds can be compared directly.
19#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
20pub enum LibVer {
21 /// The earliest format (HDF5 1.0+): version 0/1 superblock, v1
22 /// symbol-table groups. Readable by every released HDF5 library.
23 Earliest,
24 /// HDF5 1.8: version 2 superblock and the "new style" (version 2) object
25 /// headers, dense link/attribute storage, and the v2 B-tree indices.
26 V18,
27 /// HDF5 1.10: version 3 superblock, plus SWMR and the extensible/fixed
28 /// array chunk indices. This is the format this crate's writer emits.
29 V110,
30 /// HDF5 1.12.
31 V112,
32 /// HDF5 1.14.
33 V114,
34}
35
36impl LibVer {
37 /// The newest boundary this enum knows about — the meaning of
38 /// `H5F_LIBVER_LATEST`. Tracks the highest concrete variant.
39 pub const LATEST: LibVer = LibVer::V114;
40
41 /// The on-disk format this crate's [`FileBuilder`](crate::FileBuilder)
42 /// produces: the version 3 superblock introduced in HDF5 1.10.
43 pub const WRITER_OUTPUT: LibVer = LibVer::V110;
44
45 /// The minimum library version required to read a file with the given
46 /// superblock version — i.e. the *low bound* the on-disk format implies.
47 ///
48 /// Superblock 0/1 → [`Earliest`](LibVer::Earliest); 2 → [`V18`](LibVer::V18);
49 /// 3 and anything newer → [`V110`](LibVer::V110).
50 pub fn from_superblock_version(version: u8) -> LibVer {
51 match version {
52 0 | 1 => LibVer::Earliest,
53 2 => LibVer::V18,
54 _ => LibVer::V110,
55 }
56 }
57
58 /// A short, stable label for diagnostics (e.g. error messages).
59 pub fn name(self) -> &'static str {
60 match self {
61 LibVer::Earliest => "earliest",
62 LibVer::V18 => "v1.8",
63 LibVer::V110 => "v1.10",
64 LibVer::V112 => "v1.12",
65 LibVer::V114 => "v1.14",
66 }
67 }
68}