pub struct SetVersion { /* private fields */ }
Expand description
A SetVer version specification.
§Implementation details
This struct is implemented using HashSet from the standard library. Therefore, it is not usable in no-std environments right now.
Implementations§
Source§impl SetVersion
impl SetVersion
Sourcepub fn setver_compare(&self, other: &SetVersion) -> f32
pub fn setver_compare(&self, other: &SetVersion) -> f32
Implements the SetVer comparison function, as per the specification.
The only returned values are 0, 1, Infinity and NaN.
Sourcepub fn is_subset(&self, other: &SetVersion) -> bool
pub fn is_subset(&self, other: &SetVersion) -> bool
Returns whether this SetVer version is a subset of the other version, according to standard set laws.
use setver::SetVersion;
let first_version: SetVersion = "{}".parse().unwrap();
let second_version: SetVersion = "{{}}".parse().unwrap();
assert!(first_version.is_subset(&second_version));
Sourcepub fn is_strict_subset(&self, other: &SetVersion) -> bool
pub fn is_strict_subset(&self, other: &SetVersion) -> bool
Returns whether this SetVer version is a strict subset of the other version, according to standard set laws.
Sourcepub fn is_superset(&self, other: &SetVersion) -> bool
pub fn is_superset(&self, other: &SetVersion) -> bool
Returns whether this SetVer version is a superset of the other version, according to standard set laws.
Sourcepub fn is_strict_superset(&self, other: &SetVersion) -> bool
pub fn is_strict_superset(&self, other: &SetVersion) -> bool
Returns whether this SetVer version is a strict superset of the other version, according to standard set laws.
Sourcepub fn add_child_version(&mut self, child: Rc<SetVersion>) -> &mut Self
pub fn add_child_version(&mut self, child: Rc<SetVersion>) -> &mut Self
Adds the given version as a child version. This is useful when constructing a parent version for one or many previous child versions.
Examples found in repository?
5fn main() {
6 let mut args = args();
7 args.next();
8
9 if let Some(number_str) = args.next() {
10 let number = number_str.trim().parse::<usize>().expect("version is not an integer");
11
12 // This is exactly how natural numbers (including zero) work in set theory.
13 // Some dynamic programming makes this ~ 1/2 O(n^2).
14 let mut previous_number_setvers = Vec::with_capacity(number);
15 previous_number_setvers.push(Rc::new(SetVersion::default()));
16
17 for n in 1..=number {
18 let mut n_version = SetVersion::default();
19 for i in 0..n {
20 n_version.add_child_version(previous_number_setvers[i].clone());
21 }
22 previous_number_setvers.push(Rc::new(n_version));
23 }
24
25 let number_version = previous_number_setvers.last().unwrap();
26 println!("{}", number_version);
27 } else {
28 eprintln!("usage: number_to_setver NUMBER");
29 }
30}
Sourcepub fn to_integralternative(&self) -> u128
pub fn to_integralternative(&self) -> u128
Implements the Integralternative. This is the same as converting a SetVersion
into an u128
.
§Panics
For obvious reasons (if you know how the integralternative works), SetVersions with more than 128 braces in their text representation cannot be stored in a u128.
In this case, this function will panic. Use to_integralternative_bytes
instead.
Examples found in repository?
4fn main() {
5 let mut args = args();
6 args.next();
7 if let Some(mut version) = args.next() {
8 if &version == "-" {
9 version = String::new();
10 std::io::stdin().read_line(&mut version).expect("couldn't read setver from stdin");
11 version = version.trim().to_owned();
12 }
13
14 let canonicalized = version.parse::<SetVersion>().expect("invalid setver version");
15 let canonicalized_str = canonicalized.to_string();
16 let original_width = version.len().max("direct".len());
17 let canonical_width = canonicalized_str.len().max("canonicalized".len());
18 println!(
19 " {:>original_width$} {:>canonical_width$}
20set representation {:>original_width$} {:>canonical_width$}
21integralternative {:>original_width$} {:>canonical_width$}",
22 "direct",
23 "canonicalized",
24 version,
25 canonicalized_str,
26 SetVersion::string_to_integralternative(&version),
27 canonicalized.to_integralternative(),
28 original_width = original_width,
29 canonical_width = canonical_width
30 );
31 } else {
32 eprintln!("usage: alternative_representations SETVER_VERSION");
33 }
34}
Sourcepub fn string_to_integralternative(setver: &str) -> u128
pub fn string_to_integralternative(setver: &str) -> u128
Implements the Integralternative and operates on a string. This is convenient if the canonicalized form of the given setver spec is different from the string.
§Panics
For obvious reasons (if you know how the integralternative works), SetVersions with more than 128 braces in their text representation cannot be stored in a u128.
In this case, this function will panic. Use to_integralternative_bytes
instead.
Examples found in repository?
4fn main() {
5 let mut args = args();
6 args.next();
7 if let Some(mut version) = args.next() {
8 if &version == "-" {
9 version = String::new();
10 std::io::stdin().read_line(&mut version).expect("couldn't read setver from stdin");
11 version = version.trim().to_owned();
12 }
13
14 let canonicalized = version.parse::<SetVersion>().expect("invalid setver version");
15 let canonicalized_str = canonicalized.to_string();
16 let original_width = version.len().max("direct".len());
17 let canonical_width = canonicalized_str.len().max("canonicalized".len());
18 println!(
19 " {:>original_width$} {:>canonical_width$}
20set representation {:>original_width$} {:>canonical_width$}
21integralternative {:>original_width$} {:>canonical_width$}",
22 "direct",
23 "canonicalized",
24 version,
25 canonicalized_str,
26 SetVersion::string_to_integralternative(&version),
27 canonicalized.to_integralternative(),
28 original_width = original_width,
29 canonical_width = canonical_width
30 );
31 } else {
32 eprintln!("usage: alternative_representations SETVER_VERSION");
33 }
34}
Sourcepub fn to_integralternative_bytes(&self) -> Vec<u8> ⓘ
pub fn to_integralternative_bytes(&self) -> Vec<u8> ⓘ
Implements the Integralternative.
The return value is not as practical as the one of to_integralternative
, but it can always represent the integralternative and will never panic.
The returned bytes are in LSB-first order (little-endian).
Sourcepub fn string_to_integralternative_bytes(setver: &str) -> Vec<u8> ⓘ
pub fn string_to_integralternative_bytes(setver: &str) -> Vec<u8> ⓘ
Implements the Integralternative but operates directly on a string.
This is convenient if the canonicalized form of the given setver spec is different from the string.
The return value is not as practical as the one of to_integralternative
, but it can always represent the integralternative and will never panic.
The returned bytes are in LSB-first order (little-endian).
Trait Implementations§
Source§impl Clone for SetVersion
impl Clone for SetVersion
Source§fn clone(&self) -> SetVersion
fn clone(&self) -> SetVersion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more