pub struct KernelVersion { /* private fields */ }sys only.Expand description
Kernel version.
This type provides type-safe kernel version numbers with three numeric components (major, minor, patch) and an optional release string.
§Format
Kernel version format: major.minor.patch[-release]
- Major: Major version number (e.g., 6 for Linux 6.x)
- Minor: Minor version number (e.g., 8 for Linux 6.8)
- Patch: Patch level (e.g., 0 for Linux 6.8.0)
- Release: Optional release string (e.g., “40-generic” for Ubuntu)
§Invariants
- Major, minor, and patch versions are always present (u16)
- Release string is optional and must not contain leading ‘-’
- All version numbers are non-negative
§Examples
use bare_types::sys::KernelVersion;
// Create from components
let version = KernelVersion::new(6, 8, 0);
// With release string
let version = KernelVersion::with_release(6, 8, 0, "40-generic");
// Parse from string
let version: KernelVersion = "6.8.0-40-generic".parse()?;
assert_eq!(version.major(), 6);
assert_eq!(version.release(), Some("40-generic"));Implementations§
Source§impl KernelVersion
impl KernelVersion
Sourcepub const fn new(major: u16, minor: u16, patch: u16) -> Self
pub const fn new(major: u16, minor: u16, patch: u16) -> Self
Creates a new kernel version from components.
§Arguments
major- The major version numberminor- The minor version numberpatch- The patch version number
To include a release string, use KernelVersion::with_release.
§Examples
use bare_types::sys::KernelVersion;
// Simple version
let version = KernelVersion::new(6, 8, 0);
assert_eq!(version.major(), 6);
assert_eq!(version.minor(), 8);
assert_eq!(version.patch(), 0);
assert_eq!(version.release(), None);
// With release string
let version = KernelVersion::with_release(6, 8, 0, "40-generic");
assert_eq!(version.release(), Some("40-generic"));Sourcepub fn with_release(major: u16, minor: u16, patch: u16, release: &str) -> Self
pub fn with_release(major: u16, minor: u16, patch: u16, release: &str) -> Self
Creates a new kernel version with a release string.
This is a convenience method for creating a kernel version with
a release/build string. For versions without a release string,
use KernelVersion::new.
§Examples
use bare_types::sys::KernelVersion;
let version = KernelVersion::with_release(6, 8, 0, "40-generic");
assert_eq!(version.release(), Some("40-generic"));Sourcepub const fn major(&self) -> u16
pub const fn major(&self) -> u16
Returns the major version number.
§Examples
use bare_types::sys::KernelVersion;
let version = KernelVersion::new(6, 8, 0);
assert_eq!(version.major(), 6);Sourcepub const fn minor(&self) -> u16
pub const fn minor(&self) -> u16
Returns the minor version number.
§Examples
use bare_types::sys::KernelVersion;
let version = KernelVersion::new(6, 8, 0);
assert_eq!(version.minor(), 8);Sourcepub const fn patch(&self) -> u16
pub const fn patch(&self) -> u16
Returns the patch version number.
§Examples
use bare_types::sys::KernelVersion;
let version = KernelVersion::new(6, 8, 0);
assert_eq!(version.patch(), 0);Sourcepub fn release(&self) -> Option<&str>
pub fn release(&self) -> Option<&str>
Returns the optional release string.
§Examples
use bare_types::sys::KernelVersion;
let version = KernelVersion::with_release(6, 8, 0, "40-generic");
assert_eq!(version.release(), Some("40-generic"));
let version = KernelVersion::new(6, 8, 0);
assert_eq!(version.release(), None);Sourcepub const fn is_development(&self) -> bool
pub const fn is_development(&self) -> bool
Returns true if this is a development/pre-release kernel.
A kernel is considered a development kernel if the minor version is odd (Linux convention: odd minor = development, even = stable).
§Examples
use bare_types::sys::KernelVersion;
// Development kernels have odd minor versions
assert!(KernelVersion::new(6, 7, 0).is_development());
// Stable kernels have even minor versions
assert!(!KernelVersion::new(6, 8, 0).is_development());Sourcepub const fn is_stable(&self) -> bool
pub const fn is_stable(&self) -> bool
Returns true if this is a stable kernel.
A kernel is considered stable if the minor version is even (Linux convention).
§Examples
use bare_types::sys::KernelVersion;
assert!(KernelVersion::new(6, 8, 0).is_stable());
assert!(!KernelVersion::new(6, 7, 0).is_stable());Sourcepub fn is_lts(&self) -> bool
pub fn is_lts(&self) -> bool
Returns true if this is a long-term support (LTS) kernel.
This checks if the release string contains “lts” (case-insensitive). Note: This is a heuristic and may not be accurate for all distros.
§Examples
use bare_types::sys::KernelVersion;
let lts = KernelVersion::with_release(6, 1, 0, "lts");
assert!(lts.is_lts());
let regular = KernelVersion::new(6, 8, 0);
assert!(!regular.is_lts());Sourcepub const fn as_tuple(&self) -> (u16, u16, u16)
pub const fn as_tuple(&self) -> (u16, u16, u16)
Returns a tuple of (major, minor, patch) for comparison.
§Examples
use bare_types::sys::KernelVersion;
let version = KernelVersion::new(6, 8, 0);
assert_eq!(version.as_tuple(), (6, 8, 0));Sourcepub const fn bump_patch(&self) -> Self
pub const fn bump_patch(&self) -> Self
Returns a new version with the patch level incremented.
§Examples
use bare_types::sys::KernelVersion;
let version = KernelVersion::new(6, 8, 0);
let bumped = version.bump_patch();
assert_eq!(bumped.patch(), 1);Sourcepub const fn bump_minor(&self) -> Self
pub const fn bump_minor(&self) -> Self
Returns a new version with the minor version incremented and patch reset.
§Examples
use bare_types::sys::KernelVersion;
let version = KernelVersion::new(6, 8, 5);
let bumped = version.bump_minor();
assert_eq!(bumped.minor(), 9);
assert_eq!(bumped.patch(), 0);Sourcepub const fn bump_major(&self) -> Self
pub const fn bump_major(&self) -> Self
Returns a new version with the major version incremented and others reset.
§Examples
use bare_types::sys::KernelVersion;
let version = KernelVersion::new(6, 8, 5);
let bumped = version.bump_major();
assert_eq!(bumped.major(), 7);
assert_eq!(bumped.minor(), 0);
assert_eq!(bumped.patch(), 0);Sourcepub const fn without_release(&self) -> Self
pub const fn without_release(&self) -> Self
Returns a version without the release string.
§Examples
use bare_types::sys::KernelVersion;
let version = KernelVersion::with_release(6, 8, 0, "40-generic");
let without = version.without_release();
assert_eq!(without.release(), None);
assert_eq!(without.major(), 6);Trait Implementations§
Source§impl<'a> Arbitrary<'a> for KernelVersion
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for KernelVersion
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl Clone for KernelVersion
impl Clone for KernelVersion
Source§fn clone(&self) -> KernelVersion
fn clone(&self) -> KernelVersion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more