jayver/
lib.rs

1//! # JayVer
2//!
3//! A calendar versioning scheme for binaries developed by
4//! [Emmett Jayhart](https://github.com/EmmettJayhart),
5//! built upon ISO 8601 week dates and [CalVer](https://calver.org/).
6//!
7//! JayVer follows the format: **YY**.**WW**.**PATCH**
8//!
9//! - **YY**: ISO week-numbering year minus 2000 (e.g., `25` for 2025)
10//! - **WW**: ISO 8601 week number (`1`-`53`)
11//! - **PATCH**: Incremental number for patches within same week, starting at
12//!   `0`
13//!
14//! ## Examples
15//!
16//! ```
17//! use jayver::Version;
18//!
19//! // Parse a version string
20//! let version = Version::parse("25.16.3").unwrap();
21//! assert_eq!(version.year, 25); // Year 2025 (25 + 2000)
22//! assert_eq!(version.week, 16);
23//! assert_eq!(version.patch, 3);
24//!
25//! // Create a version for the current date
26//! let today = Version::today();
27//! println!("Current version: {today}");
28//!
29//! // Compare versions
30//! let v1 = Version::parse("25.10.0").unwrap();
31//! let v2 = Version::parse("25.11.0").unwrap();
32//! assert!(v1 < v2);
33//!
34//! // Check version requirements
35//! use jayver::VersionReq;
36//! let req = VersionReq::parse(">=25.10.0").unwrap();
37//! assert!(req.matches(&v1));
38//! ```
39//!
40//! ## ISO 8601 Week Dates
41//!
42//! JayVer strictly follows ISO 8601 week dates:
43//! - Week 01 is the week containing January 4th
44//! - Weeks are numbered 01-53
45//! - The ISO week-numbering year may differ from the calendar year near year
46//!   boundaries
47
48pub mod error;
49pub mod parser;
50pub mod requirement;
51pub mod version;
52
53pub use crate::{
54    error::{Error, Result},
55    parser::{parse_version, patch, version as version_parser, week, year, year_week},
56    requirement::{AnyVersionReq, Comparator, Op, VersionReq},
57    version::{Patch, Version, Week, Year},
58};
59
60/// Quickly parse a version string without importing the Version type.
61///
62/// # Examples
63///
64/// ```
65/// let version = jayver::parse("25.16.0").unwrap();
66/// assert_eq!(version.to_string(), "25.16.0");
67/// ```
68pub fn parse<S: AsRef<str>>(s: S) -> Result<Version> {
69    Version::parse(s)
70}
71
72/// Check if a version string is valid without constructing a Version.
73///
74/// # Examples
75///
76/// ```
77/// assert!(jayver::is_valid("25.16.0"));
78/// assert!(!jayver::is_valid("25.54.0")); // Week 54 is invalid
79/// ```
80pub fn is_valid<S: AsRef<str>>(s: S) -> bool {
81    Version::parse(s).is_ok()
82}
83
84/// Create a version representing the current date with patch 0.
85///
86/// # Examples
87///
88/// ```
89/// let today = jayver::today();
90/// println!("Today's version: {}", today);
91/// ```
92pub fn today() -> Version {
93    Version::today()
94}