Enum VersionSegment

Source
pub enum VersionSegment<'a> {
    Segment {
        text: &'a str,
        delimiter_count: usize,
    },
    SubSegment {
        text: &'a str,
    },
}
Expand description

This enum 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.).

  • There’s no differentiation between delimiters represented by different characters (e.g. '$$$' == '...' == '.$-').

  • Each segment 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:

    use alpm_types::VersionSegment::*;
    vec![
      Segment { text: "1", delimiter_count: 0},
      Segment { text: "a", delimiter_count: 3},
    ];
  • 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.1foo123.0 would be represented as:

    use alpm_types::VersionSegment::*;
    vec![
      Segment { text: "1", delimiter_count: 0},
      Segment { text: "1", delimiter_count: 1},
      SubSegment { text: "foo" },
      SubSegment { text: "123" },
      Segment { text: "0", delimiter_count: 1},
    ];
  • Trailing delimiters are encoded as an empty string.

    1... would be represented as:

    use alpm_types::VersionSegment::*;
    vec![
      Segment { text: "1", delimiter_count: 0},
      Segment { text: "", delimiter_count: 3},
    ];

Variants§

§

Segment

The start of a new segment. If the current segment can be split into multiple sub-segments, this variant only contains the first sub-segment.

To figure out whether this is sub-segment, peek at the next element in the VersionSegments iterator, whether it’s a VersionSegment::SubSegment.

Fields

§text: &'a str

The string representation of this segment

§delimiter_count: usize

The amount of leading delimiters that were found for this segment

§

SubSegment

A sub-segment of a version string’s segment.

Note that the first sub-segment of a segment that can be split into sub-segments is counterintuitively represented by VersionSegment::Segment. This implementation detail is due to the way the comparison algorithm works, as it does not always differentiate between segments and sub-segments.

Fields

§text: &'a str

The string representation of this sub-segment

Implementations§

Source§

impl<'a> VersionSegment<'a>

Source

pub fn text(&self) -> &str

Returns the inner string slice independent of VersionSegment variant.

Source

pub fn is_empty(&self) -> bool

Returns whether the inner string slice is empty, independent of VersionSegment variant

Source

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

Returns an iterator over the chars of the inner string slice.

Source

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

Creates a type T from the inner string slice by relying on T’s FromStr::from_str implementation.

Source

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

Compares the inner string slice with that of another VersionSegment.

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 u8)

🔬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