Enum kube_core::Version

source ·
pub enum Version {
    Stable(u32),
    Beta(u32, Option<u32>),
    Alpha(u32, Option<u32>),
    Nonconformant(String),
}
Expand description

Version parser for Kubernetes version patterns

This type implements two orderings for sorting by:

To get the api versions sorted by kubectl priority:

use kube_core::Version;
use std::cmp::Reverse; // for DESCENDING sort
let mut versions = vec![
    "v10beta3",
    "v2",
    "foo10",
    "v1",
    "v3beta1",
    "v11alpha2",
    "v11beta2",
    "v12alpha1",
    "foo1",
    "v10",
];
versions.sort_by_cached_key(|v| Reverse(Version::parse(v).priority()));
assert_eq!(versions, vec![
    "v10",
    "v2",
    "v1",
    "v11beta2",
    "v10beta3",
    "v3beta1",
    "v12alpha1",
    "v11alpha2",
    "foo1",
    "foo10",
]);

Variants§

§

Stable(u32)

A major/GA release

Always considered higher priority than a beta release.

§

Beta(u32, Option<u32>)

A beta release for a specific major version

Always considered higher priority than an alpha release.

§

Alpha(u32, Option<u32>)

An alpha release for a specific major version

Always considered higher priority than a nonconformant version

§

Nonconformant(String)

An non-conformant api string

CRDs and APIServices can use arbitrary strings as versions.

Implementations§

source§

impl Version

source

pub fn parse(v: &str) -> Version

An infallble parse of a Kubernetes version string

use kube_core::Version;
assert_eq!(Version::parse("v10beta12"), Version::Beta(10, Some(12)));
source§

impl Version

source

pub fn priority(&self) -> impl Ord

An Ord for Version that orders by Kubernetes version priority

This order will favour stable versions over newer pre-releases and is used by kubectl.

For example:

assert!(Version::Stable(2).priority() > Version::Stable(1).priority());
assert!(Version::Stable(1).priority() > Version::Beta(1, None).priority());
assert!(Version::Stable(1).priority() > Version::Beta(2, None).priority());
assert!(Version::Stable(2).priority() > Version::Alpha(1, Some(2)).priority());
assert!(Version::Stable(1).priority() > Version::Alpha(2, Some(2)).priority());
assert!(Version::Beta(1, None).priority() > Version::Nonconformant("ver3".into()).priority());

Note that the type of release matters more than the version numbers: Stable(x) > Beta(y) > Alpha(z) > Nonconformant(w) for all x,y,z,w

Nonconformant versions are ordered alphabetically.

source

pub fn generation(&self) -> impl Ord

An Ord for Version that orders by version generation

This order will favour higher version numbers even if it’s a pre-release.

For example:

assert!(Version::Stable(2).generation() > Version::Stable(1).generation());
assert!(Version::Stable(1).generation() > Version::Beta(1, None).generation());
assert!(Version::Beta(2, None).generation() > Version::Stable(1).generation());
assert!(Version::Stable(2).generation() > Version::Alpha(1, Some(2)).generation());
assert!(Version::Alpha(2, Some(2)).generation() > Version::Stable(1).generation());
assert!(Version::Beta(1, None).generation() > Version::Nonconformant("ver3".into()).generation());

Trait Implementations§

source§

impl Clone for Version

source§

fn clone(&self) -> Version

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Version

source§

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

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

impl FromStr for Version

An infallible FromStr implementation for more generic users

§

type Err = Infallible

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for Version

source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Version

source§

impl StructuralPartialEq for Version

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

fn __clone_box(&self, _: Private) -> *mut ()

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,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.