pub struct SemanticVersion {
pub version: Version,
pub prerelease: String,
pub build_metadata: String,
}Expand description
Describes a numeric version with optional prerelease and build metadata.
Unlike crates that accept only SemVer 2, this type intentionally supports
the two- to four-part version grammar used by Nerdbank.GitVersioning, along
with the {height} macro in prerelease and build metadata identifiers.
Fields§
§version: VersionThe numeric portion of the version.
prerelease: StringThe prerelease portion, including its leading hyphen, or an empty string.
build_metadata: StringThe build metadata, including its leading plus, or an empty string.
Implementations§
Source§impl SemanticVersion
impl SemanticVersion
Sourcepub fn new(
version: Version,
prerelease: impl Into<String>,
build_metadata: impl Into<String>,
) -> Result<Self>
pub fn new( version: Version, prerelease: impl Into<String>, build_metadata: impl Into<String>, ) -> Result<Self>
Initializes a semantic version, validating the prerelease and build metadata strings.
Sourcepub fn try_parse(value: &str) -> Option<Self>
pub fn try_parse(value: &str) -> Option<Self>
Parses a semantic version, returning None when the input is invalid.
Sourcepub fn version_height_position(&self) -> Option<VersionPosition>
pub fn version_height_position(&self) -> Option<VersionPosition>
Gets the position where version height should appear.
Sourcepub fn git_commit_id_position(&self) -> Option<VersionPosition>
pub fn git_commit_id_position(&self) -> Option<VersionPosition>
Gets the position where the first 16 bits of a Git commit ID should appear, if any.
Sourcepub fn read_version_position(&self, position: VersionPosition) -> Result<i64>
pub fn read_version_position(&self, position: VersionPosition) -> Result<i64>
Reads one of the four numeric version positions, using -1 for an
unspecified build or revision.
Sourcepub fn will_version_change_reset_version_height(
first: &Self,
second: &Self,
version_height_position: VersionPosition,
) -> Result<bool>
pub fn will_version_change_reset_version_height( first: &Self, second: &Self, version_height_position: VersionPosition, ) -> Result<bool>
Tests whether changing between two semantic versions resets version height at the specified position.
Sourcepub fn is_matching_version(&self, version: &Version) -> bool
pub fn is_matching_version(&self, version: &Version) -> bool
Checks whether a numeric version may have been produced by this semantic version specification.
Sourcepub fn contains(&self, version: &Version) -> bool
pub fn contains(&self, version: &Version) -> bool
Checks whether a numeric version belongs to the set represented by this semantic version specification.
Sourcepub fn increment(&self, increment: ReleaseVersionIncrement) -> Result<Self>
pub fn increment(&self, increment: ReleaseVersionIncrement) -> Result<Self>
Gets a new semantic version with the specified numeric component incremented.
Incrementing build is invalid when the build component is unspecified. Components after the incremented component are reset to zero while the original component count, prerelease, and build metadata are preserved.
Sourcepub fn set_first_prerelease_tag(&self, new_first_tag: &str) -> Result<Self>
pub fn set_first_prerelease_tag(&self, new_first_tag: &str) -> Result<Self>
Sets the first prerelease identifier. The leading hyphen may be specified or omitted. An empty value removes the first identifier.
Returns a copy without any prerelease identifiers.
Sourcepub fn make_prerelease_semver1_compliant(
prerelease: &str,
padding_size: usize,
) -> String
pub fn make_prerelease_semver1_compliant( prerelease: &str, padding_size: usize, ) -> String
Converts a SemVer 2 prerelease such as -beta.5 to a SemVer 1
compatible value such as -beta-0005.
Numeric identifiers are left-padded to at least padding_size digits,
and dots are replaced by hyphens.