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:
Version::priority
for Kubernetes/kubectl version priorityVersion::generation
for sorting strictly by version generation in a semver style
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
impl Version
sourcepub fn priority(&self) -> impl Ord
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.
sourcepub fn generation(&self) -> impl Ord
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§
impl Eq for Version
impl StructuralPartialEq for Version
Auto Trait Implementations§
impl Freeze for Version
impl RefUnwindSafe for Version
impl Send for Version
impl Sync for Version
impl Unpin for Version
impl UnwindSafe for Version
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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.