Skip to main content

VersionPolicy

Enum VersionPolicy 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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 ..

Fields

§majors: Vec<u64>

Accepted major numbers, for example [0, 1].

Implementations§

Source§

impl VersionPolicy

Source

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

Source§

fn clone(&self) -> VersionPolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VersionPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VersionPolicy

Source§

fn default() -> VersionPolicy

Returns the “default value” for a type. Read more
Source§

impl Display for VersionPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for VersionPolicy

Source§

impl PartialEq for VersionPolicy

Source§

fn eq(&self, other: &VersionPolicy) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for VersionPolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.