Skip to main content

parse

Function parse 

Source
pub fn parse(version: &str) -> Result<(u64, u64, u64), Error>
Expand description

Parse a MAJOR.MINOR.PATCH string into its three numeric components.

The form is exactly three dot-separated integers, each either 0 or a non-zero digit followed by digits — i.e. no leading zeros, no sign, no pre-release/build suffix (SPEC §9: 01.2.0, 1.2.0-rc1, "0", "0.1", "1.2.3.4" are all rejected). This matches the tightened JSON schema pattern ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$, so validate and the schema agree on what is well-formed.

assert_eq!(ledvar_core::parse_major("0.3.1").unwrap(), 0);
assert!(ledvar_core::parse_major("0.3").is_err());   // not MAJOR.MINOR.PATCH
assert!(ledvar_core::parse_major("01.2.0").is_err()); // leading zero