SemanticVersion structv0.1.0
pub struct SemanticVersion {
pub major: uint;
pub minor: uint;
pub patch: uint;
}
Carries the core only: a pre-release tag or build metadata is not represented, so two versions differing only in those compare equal. Copy, owns nothing, and allocates nothing. Ordered by precedence, major component first, as semantic versioning defines it.
Fields
| Name | Type | Description |
|---|---|---|
major | uint | The major component, which changes when compatibility does. |
minor | uint | The minor component. |
patch | uint | The patch component. |
Constructors
SemanticVersion
pub func SemanticVersion(
major: uint,
minor: uint,
patch: uint
) -> SemanticVersion
Constructs a version with the given components. All three are read by value; the version is returned by copy and borrows nothing. Cannot fail: every triple of components is a version. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
major | uint | the major version |
minor | uint | the minor version |
patch | uint | the patch version |
Returns: the version
Methods
Compare
pub func Compare(
self: &SemanticVersion,
other: SemanticVersion
) -> int
Compares precedence with other.
self is borrowed and other is read by value. Returns a negative value when self precedes other, zero
when the two have the same precedence, and a positive value when self follows it. Components are compared
major first, and the first difference decides.
Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: how this value orders against other
IsEqualTo
pub func IsEqualTo(
self: &SemanticVersion,
other: SemanticVersion
) -> bool
Whether the two versions have the same precedence.
self is borrowed and other is read by value. Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: whether the two versions are the same
IsLessThan
pub func IsLessThan(
self: &SemanticVersion,
other: SemanticVersion
) -> bool
Whether this version precedes other.
self is borrowed and other is read by value. Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: whether this version is older
IsAtMost
pub func IsAtMost(
self: &SemanticVersion,
other: SemanticVersion
) -> bool
Whether this version precedes other or matches it.
self is borrowed and other is read by value. Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: whether this version is the same or older
IsGreaterThan
pub func IsGreaterThan(
self: &SemanticVersion,
other: SemanticVersion
) -> bool
Whether this version follows other.
self is borrowed and other is read by value. Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: whether this version is newer
IsAtLeast
pub func IsAtLeast(
self: &SemanticVersion,
other: SemanticVersion
) -> bool
Whether this version follows other or matches it, which is how a minimum requirement is written.
self is borrowed and other is read by value. Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: whether this version is the same or newer
Operators
==
pub func ==(
self: &SemanticVersion,
other: SemanticVersion
) -> bool
Equality by precedence, the operator spelling of IsEqualTo.
Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: whether the two are equal
!=
pub func !=(
self: &SemanticVersion,
other: SemanticVersion
) -> bool
Inequality by precedence. Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: whether the two differ
<
pub func <(self: &SemanticVersion, other: SemanticVersion) -> bool
Precedence ordering, the operator spelling of IsLessThan.
Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: whether this one is less
<=
pub func <=(self: &SemanticVersion, other: SemanticVersion) -> bool
Precedence ordering, the operator spelling of IsAtMost.
Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: whether this one is less or equal
>
pub func >(self: &SemanticVersion, other: SemanticVersion) -> bool
Precedence ordering, the operator spelling of IsGreaterThan.
Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: whether this one is greater
>=
pub func >=(self: &SemanticVersion, other: SemanticVersion) -> bool
Precedence ordering, the operator spelling of IsAtLeast.
Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
other | SemanticVersion | the value to compare against |
Returns: whether this one is greater or equal