pub struct VersionSegment<'a> {
pub segment: &'a str,
pub delimiters: usize,
}
Expand description
This struct 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.). -
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>
impl<'a> VersionSegment<'a>
sourcepub fn new(segment: &'a str, delimiters: usize) -> Self
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.
sourcepub fn parse<T: FromStr>(&self) -> Result<T, T::Err>
pub fn parse<T: FromStr>(&self) -> Result<T, T::Err>
Passhrough self.segment.parse()
for convenience purposes.
sourcepub fn str_cmp(&self, other: &VersionSegment<'_>) -> Ordering
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>
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 moresource§impl<'a> Debug for VersionSegment<'a>
impl<'a> Debug for VersionSegment<'a>
source§impl<'a> PartialEq for VersionSegment<'a>
impl<'a> PartialEq for VersionSegment<'a>
impl<'a> Eq for VersionSegment<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)