#[non_exhaustive]pub enum VersionPolicy {
Permissive,
RequirePresent,
CompatibleMajor {
majors: Vec<u64>,
},
}Expand description
How super::read_with treats the root /version dataset.
The default is Self::Permissive. Majors accepted by
Self::CompatibleMajor are supplied by the caller; this crate does not
keep a hidden compatibility matrix. Paper fixtures vendored under
tests/fixtures/ embed 0.1.1 / 0.2.0, and super::DEFAULT_NIR_VERSION
is 1.0.8 — a typical importer therefore passes [0, 1].
use nir_rs::io::{ReadOptions, VersionPolicy};
let tool = ReadOptions::default();
assert_eq!(tool.version_policy, VersionPolicy::Permissive);
let importer = ReadOptions::default()
.with_version_policy(VersionPolicy::compatible_major([0, 1]));
assert!(matches!(
importer.version_policy,
VersionPolicy::CompatibleMajor { .. }
));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Permissive
Accept a missing /version or any present string and store it verbatim.
Matches Python nir.read and the default super::read entry point.
RequirePresent
Reject a missing /version. Any present string is stored verbatim
without SemVer parsing.
CompatibleMajor
Parse /version as MAJOR.MINOR.PATCH with optional SemVer prerelease
(-…) and build (+…) suffixes, and accept only the listed majors.
Construct with Self::compatible_major so the allow-list is explicit.
A missing /version is a policy failure.
§Parsing
The core must be exactly three decimal components. 1.0, v1.0.0, and
01.0.0 are malformed. Numeric components must not have leading zeros
(0 itself is allowed).
Prerelease and build suffixes are parsed, then ignored for the major
check: 1.0.0-rc.1+exp.sha has major 1 and is accepted when 1 is
listed. They are not stripped from crate::NirGraph::version — the
original wire string is stored. An empty suffix (1.0.0- / 1.0.0+)
is malformed. Identifiers may contain ASCII alphanumerics and -,
separated by ..
Implementations§
Source§impl VersionPolicy
impl VersionPolicy
Sourcepub fn compatible_major(majors: impl IntoIterator<Item = u64>) -> Self
pub fn compatible_major(majors: impl IntoIterator<Item = u64>) -> Self
Accept /version strings whose SemVer major is one of majors.
Duplicates are dropped and the list is sorted so std::fmt::Display
is stable.
An empty list rejects every well-formed version (fail-closed).
Trait Implementations§
Source§impl Clone for VersionPolicy
impl Clone for VersionPolicy
Source§fn clone(&self) -> VersionPolicy
fn clone(&self) -> VersionPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VersionPolicy
impl Debug for VersionPolicy
Source§impl Default for VersionPolicy
impl Default for VersionPolicy
Source§fn default() -> VersionPolicy
fn default() -> VersionPolicy
Source§impl Display for VersionPolicy
impl Display for VersionPolicy
impl Eq for VersionPolicy
Source§impl PartialEq for VersionPolicy
impl PartialEq for VersionPolicy
impl StructuralPartialEq for VersionPolicy
Auto Trait Implementations§
impl Freeze for VersionPolicy
impl RefUnwindSafe for VersionPolicy
impl Send for VersionPolicy
impl Sync for VersionPolicy
impl Unpin for VersionPolicy
impl UnsafeUnpin for VersionPolicy
impl UnwindSafe for VersionPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.