-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathlib.rs
More file actions
54 lines (52 loc) · 1.63 KB
/
Copy pathlib.rs
File metadata and controls
54 lines (52 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! This library provides strongly-typed and validated Kubernetes API version
//! definitions. Versions consist of three major components: the optional group,
//! the mandatory major version and the optional level. The format can be
//! described by `(<GROUP>/)<VERSION>`, with `<VERSION>` being defined as
//! `v<MAJOR>(alpha<LEVEL>|beta<LEVEL>)`.
//!
//! ## Usage
//!
//! ### Parsing from [`str`]
//!
//! Versions can be parsed and validated from [`str`] using Rust's standard
//! [`FromStr`](std::str::FromStr) trait.
//!
//! ```
//! # use std::str::FromStr;
//! use k8s_version::ApiVersion;
//!
//! let api_version = ApiVersion::from_str("extensions/v1beta1").unwrap();
//!
//! // Or using .parse()
//! let api_version: ApiVersion = "extensions/v1beta1".parse().unwrap();
//! ```
//!
//! ### Constructing
//!
//! Alternatively, they can be constructed programatically using the
//! [`ApiVersion::new()`] and [`ApiVersion::try_new()`] functions.
//!
//! ```
//! # use std::str::FromStr;
//! use k8s_version::{ApiVersion, Group, Level, Version};
//!
//! let version = Version::new(1, Some(Level::Beta(1)));
//! let group = Group::from_str("extension").unwrap();
//! let api_version = ApiVersion::new(Some(group), version);
//!
//! assert_eq!(api_version.to_string(), "extension/v1beta1");
//!
//! // Or using ::try_new()
//! let version = Version::new(1, Some(Level::Beta(1)));
//! let api_version = ApiVersion::try_new(Some("extension"), version).unwrap();
//!
//! assert_eq!(api_version.to_string(), "extension/v1beta1");
//! ```
mod api_version;
mod group;
mod level;
mod version;
pub use api_version::*;
pub use group::*;
pub use level::*;
pub use version::*;