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.
VersionSegment
s 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
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.
Implementations§
Source§impl<'a> VersionSegment<'a>
impl<'a> VersionSegment<'a>
Sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
Returns the inner string slice independent of VersionSegment
variant.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the inner string slice is empty, independent of VersionSegment
variant
Sourcepub fn parse<T: FromStr>(&self) -> Result<T, T::Err>
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.
Sourcepub fn str_cmp(&self, other: &VersionSegment<'_>) -> Ordering
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>
impl<'a> Clone for VersionSegment<'a>
Source§fn clone(&self) -> VersionSegment<'a>
fn clone(&self) -> VersionSegment<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more