alpm_types::version

Struct VersionSegment

source
pub struct VersionSegment<'a> {
    pub segment: &'a str,
    pub delimiters: usize,
}
Expand description

This struct represents a single segment in a version string. VersionSegments are returned by the VersionSegments iterator, which is responsible for splitting a version string into its segments.

Version strings are split according to the following rules:

  • Non-alphanumeric characters always count as delimiters (., -, $, etc.).

  • Each segment also contains the info about the amount of leading delimiters for that segment. Leading delimiters that directly follow after one another are grouped together. The length of the delimiters is important, as it plays a crucial role in the algorithm that determines which version is newer.

    1...a would be represented as:

    [
      (segment: "1", delimiters: 0),
      (segment: "a", delimiters: 3)
    ]
  • There’s no differentiation between different delimiters. '$$$' == '...' == '.$-'

  • Alphanumeric strings are also split into individual sub-segments. This is done by walking over the string and splitting it every time a switch from alphabetic to numeric is detected or vice versa.

    1.1asdf123.0 would be represented as:

    [
      (segment: "1", delimiters: 0),
      (segment: "1", delimiters: 1)
      (segment: "asdf", delimiters: 0)
      (segment: "123", delimiters: 0)
      (segment: "0", delimiters: 1)
    ]
  • Trailing delimiters are encoded as an empty string.

    1... would be represented as:

    [
      (segment: "1", delimiters: 0),
      (segment: "", delimiters: 3),
    ]

Fields§

§segment: &'a str

The string representation of the next segment

§delimiters: usize

The amount of leading delimiters that were found for this segment

Implementations§

source§

impl<'a> VersionSegment<'a>

source

pub fn new(segment: &'a str, delimiters: usize) -> Self

Create a new instance of a VersionSegment consisting of the segment’s string and the amount of leading delimiters.

source

pub fn is_empty(&self) -> bool

Passhrough to self.segment.is_empty() for convenience purposes.

source

pub fn chars(&self) -> Chars<'a>

Passhrough to self.segment.chars() for convenience purposes.

source

pub fn parse<T: FromStr>(&self) -> Result<T, T::Err>

Passhrough self.segment.parse() for convenience purposes.

source

pub fn str_cmp(&self, other: &VersionSegment<'_>) -> Ordering

Compare the self’s segment string with segment string of other.

Trait Implementations§

source§

impl<'a> Clone for VersionSegment<'a>

source§

fn clone(&self) -> VersionSegment<'a>

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<'a> Debug for VersionSegment<'a>

source§

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

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

impl<'a> PartialEq for VersionSegment<'a>

source§

fn eq(&self, other: &VersionSegment<'a>) -> 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<'a> Eq for VersionSegment<'a>

source§

impl<'a> StructuralPartialEq for VersionSegment<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for VersionSegment<'a>

§

impl<'a> RefUnwindSafe for VersionSegment<'a>

§

impl<'a> Send for VersionSegment<'a>

§

impl<'a> Sync for VersionSegment<'a>

§

impl<'a> Unpin for VersionSegment<'a>

§

impl<'a> UnwindSafe for VersionSegment<'a>

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, 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> 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, 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.
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T