pub fn parse_version(input: &str) -> Result<Version>Expand description
Parses a version header from AIM markup format.
This function parses version headers in the format [epoch] or [epoch:partial]
as used in AIM files. The version header is surrounded by square brackets
and may contain optional whitespace around the entire header.
§Format
[1]- Version with epoch 1 and implicit partial 0[1:2]- Version with epoch 1 and partial 2[ 123 ]- Version with epoch 123 and implicit partial 0 (whitespace allowed)[ 1:2 ]- Version with epoch 1 and partial 2 (whitespace allowed)
§Parameters
input- The string containing the version header to parse
§Returns
Ok(Version)- The parsed version with epoch and optional partialErr(anyhow::Error)- Parse error with descriptive message
§Examples
use aimx::aim::parse_version;
// Parse simple version
let version = parse_version("[1]").unwrap();
assert_eq!(version.epoc(), 1);
assert_eq!(version.partial(), 0);
// Parse version with partial
let version = parse_version("[2:3]").unwrap();
assert_eq!(version.epoc(), 2);
assert_eq!(version.partial(), 3);
// Parse with whitespace around header
let version = parse_version("[ 45 ]").unwrap();
assert_eq!(version.epoc(), 45);
assert_eq!(version.partial(), 0);
// Invalid formats return errors
assert!(parse_version("1").is_err()); // Missing brackets
assert!(parse_version("[1:]").is_err()); // Missing partial
assert!(parse_version("[]").is_err()); // Missing version