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
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.
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
An infallible FromStr implementation for more generic users
Auto Trait Implementations
impl RefUnwindSafe for Version
impl UnwindSafe for Version
Blanket Implementations
Mutably borrows from an owned value. Read more