Version

Struct Version 

Source
pub struct Version {
    pub major: u32,
    pub minor: u32,
    pub micro: u32,
    pub patch: Option<u32>,
    pub status: Option<String>,
}
Expand description

A parsed Tor version with comparison support.

Represents a Tor version in the format major.minor.micro[.patch][-status]. Versions can be parsed from strings, compared, and converted back to strings.

§Invariants

  • major, minor, and micro are always present
  • patch is None if not specified in the version string
  • status is None if no status tag was present
  • When comparing, missing patch is treated as 0

§Comparison

Versions implement Ord with the following semantics:

  • Numeric components are compared in order: major → minor → micro → patch
  • Status tags affect ordering: dev < alpha < beta < rc < release
  • Two versions differing only by unknown status tags are considered equal

§Example

use stem_rs::Version;

let alpha = Version::parse("0.4.7.1-alpha").unwrap();
let beta = Version::parse("0.4.7.1-beta").unwrap();
let release = Version::parse("0.4.7.1").unwrap();

assert!(alpha < beta);
assert!(beta < release);

// Missing patch is treated as 0 for ordering (but not equality)
let v1 = Version::parse("0.4.7").unwrap();
let v2 = Version::parse("0.4.7.0").unwrap();
use std::cmp::Ordering;
assert_eq!(v1.cmp(&v2), Ordering::Equal);

Fields§

§major: u32

Major version number.

Historically, Tor major versions have been 0.x.y.z.

§minor: u32

Minor version number.

Incremented for significant feature releases.

§micro: u32

Micro version number.

Incremented for smaller feature releases within a minor version.

§patch: Option<u32>

Patch level, if specified.

Used for bug-fix releases. When comparing versions, None is treated as 0.

§status: Option<String>

Release status tag, if present.

Common values include:

  • "dev" - Development build
  • "alpha" - Alpha release
  • "beta" - Beta release
  • "rc" or "rc1", "rc2", etc. - Release candidate
  • None - Stable release

Status affects version comparison: dev < alpha < beta < rc < release.

Implementations§

Source§

impl Version

Source

pub fn new(major: u32, minor: u32, micro: u32) -> Self

Creates a new version with the specified major, minor, and micro components.

The patch level defaults to None and status defaults to None, representing a stable release.

§Example
use stem_rs::Version;

let v = Version::new(0, 4, 7);
assert_eq!(v.to_string(), "0.4.7");
assert_eq!(v.patch, None);
assert_eq!(v.status, None);
Source

pub fn with_patch(self, patch: u32) -> Self

Sets the patch level for this version.

This is a builder method that consumes and returns self, allowing method chaining.

§Example
use stem_rs::Version;

let v = Version::new(0, 4, 7).with_patch(1);
assert_eq!(v.patch, Some(1));
assert_eq!(v.to_string(), "0.4.7.1");
Source

pub fn with_status(self, status: impl Into<String>) -> Self

Sets the status tag for this version.

This is a builder method that consumes and returns self, allowing method chaining.

§Status Tags and Comparison

The status tag affects version comparison:

  • "dev" versions are less than "alpha"
  • "alpha" versions are less than "beta"
  • "beta" versions are less than "rc" (release candidate)
  • "rc" versions are less than stable releases (no status)
§Example
use stem_rs::Version;

let alpha = Version::new(0, 4, 7).with_status("alpha");
let beta = Version::new(0, 4, 7).with_status("beta");
let release = Version::new(0, 4, 7);

assert!(alpha < beta);
assert!(beta < release);
assert_eq!(alpha.to_string(), "0.4.7-alpha");
Source

pub fn parse(s: &str) -> Result<Self, Error>

Parses a version string into a Version.

This is a convenience wrapper around FromStr::from_str.

§Format

The version string format is: major.minor.micro[.patch][-status][ (extra)]

  • major, minor, micro: Required numeric components
  • patch: Optional fourth numeric component
  • status: Optional status tag after - (e.g., “alpha”, “beta”, “rc1”)
  • extra: Optional parenthesized info (e.g., git commit) - parsed but not stored
§Errors

Returns Error::Parse if:

  • The string is empty
  • Numeric components cannot be parsed as u32
  • The format is otherwise invalid
§Example
use stem_rs::Version;

// Simple version
let v = Version::parse("0.4.7").unwrap();
assert_eq!((v.major, v.minor, v.micro), (0, 4, 7));

// Version with patch and status
let v = Version::parse("0.4.7.1-alpha").unwrap();
assert_eq!(v.patch, Some(1));
assert_eq!(v.status, Some("alpha".to_string()));

// Version with git commit info (extra info is parsed but not stored)
let v = Version::parse("0.4.7.1 (git-abc123)").unwrap();
assert_eq!(v.patch, Some(1));

// Invalid versions
assert!(Version::parse("").is_err());
assert!(Version::parse("not.a.version").is_err());

Trait Implementations§

Source§

impl Clone for Version

Source§

fn clone(&self) -> Version

Returns a duplicate 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 Display for Version

Formats the version as a string.

The output format is major.minor.micro[.patch][-status].

§Example

use stem_rs::Version;

let v = Version::new(0, 4, 7).with_patch(1).with_status("alpha");
assert_eq!(format!("{}", v), "0.4.7.1-alpha");

let v = Version::new(0, 4, 7);
assert_eq!(format!("{}", v), "0.4.7");
Source§

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

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

impl FromStr for Version

Parses a Version from a string.

See Version::parse for format details and examples.

Source§

type Err = Error

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 Hash for Version

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Version

Provides total ordering for versions.

Versions are compared component by component in this order:

  1. major - compared numerically
  2. minor - compared numerically
  3. micro - compared numerically
  4. patch - compared numerically (None treated as 0)
  5. status - compared by release priority

§Status Priority

Status tags are ordered by release maturity:

  • dev < alpha < beta < rc < (no status)
  • Unknown status tags are treated as release versions

§Example

use stem_rs::Version;

// Numeric comparison
assert!(Version::parse("0.4.7").unwrap() < Version::parse("0.4.8").unwrap());
assert!(Version::parse("0.4.7").unwrap() < Version::parse("0.5.0").unwrap());

// Status comparison
assert!(Version::parse("0.4.7-dev").unwrap() < Version::parse("0.4.7-alpha").unwrap());
assert!(Version::parse("0.4.7-alpha").unwrap() < Version::parse("0.4.7-beta").unwrap());
assert!(Version::parse("0.4.7-beta").unwrap() < Version::parse("0.4.7-rc1").unwrap());
assert!(Version::parse("0.4.7-rc1").unwrap() < Version::parse("0.4.7").unwrap());

// Missing patch is treated as 0 for ordering
use std::cmp::Ordering;
assert_eq!(Version::parse("0.4.7").unwrap().cmp(&Version::parse("0.4.7.0").unwrap()), Ordering::Equal);
Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. 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 PartialOrd for Version

Provides partial ordering for versions.

This implementation delegates to Ord::cmp, so all versions are comparable. See Ord implementation for comparison semantics.

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
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§

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<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> Same for T

Source§

type Output = T

Should always be Self
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 = 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>,

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.