pub struct Version {
pub major: u64,
pub minor: u64,
pub patch: u64,
pub pre: Option<String>,
}Fields§
§major: u64§minor: u64§patch: u64§pre: Option<String>Prerelease identifier without the leading hyphen (e.g. “rc.1”).
Implementations§
Source§impl Version
impl Version
Sourcepub fn parse(tag_str: &str, tag_prefix: &str) -> Option<Self>
pub fn parse(tag_str: &str, tag_prefix: &str) -> Option<Self>
Parse a semantic version from a tag string with optional prefix. Tries to parse with prefix first, then without prefix. Examples: “v1.2.3” with prefix “v” -> Some(Version { 1, 2, 3 }) “1.2.3” with prefix “v” -> Some(Version { 1, 2, 3 }) (fallback)
Sourcepub fn format(&self, tag_prefix: &str) -> String
pub fn format(&self, tag_prefix: &str) -> String
Format version as a semantic version string with tag prefix. Examples: Version { 1, 2, 3 } with prefix “v” -> “v1.2.3”
Sourcepub fn to_semver(&self) -> String
pub fn to_semver(&self) -> String
Format version as semantic version string without prefix. Examples: Version { 1, 2, 3 } -> “1.2.3”
Sourcepub fn is_prerelease(&self) -> bool
pub fn is_prerelease(&self) -> bool
Whether this version is a prerelease (e.g. 1.2.3-rc.1).
Sourcepub fn with_prerelease(&self, label: &str, existing: &[Version]) -> Self
pub fn with_prerelease(&self, label: &str, existing: &[Version]) -> Self
Attach a prerelease label. A bare label such as rc is numbered one
past the highest matching rc.N in existing; a label that already
carries identifiers (rc.2, beta.1) is used as given.
Sourcepub fn with_bump(&self, bump: BumpLevel) -> Self
pub fn with_bump(&self, bump: BumpLevel) -> Self
Increment version based on bump level.
- Major: increment major, reset minor and patch
- Minor: increment minor, reset patch
- Patch: increment patch
- None: return current version unchanged
A prerelease is promoted to its release instead (1.2.0-rc.2 -> 1.2.0),
since the prerelease already carries the bump.