Lines Matching full:version
3 /// Version number: `major.minor.patch`, ignoring release channel.
5 pub struct Version(u64); struct
7 impl Version { implementation
8 /// Reads the version of the running compiler. If it cannot be determined
14 /// use version_check::Version;
16 /// match Version::read() {
17 /// Some(d) => format!("Version is: {}", d),
18 /// None => format!("Failed to read the version.")
21 pub fn read() -> Option<Version> { in read()
23 .and_then(|(version, _)| version) in read()
24 .and_then(|version| Version::parse(&version)) in read()
28 /// Parse a Rust release version (of the form
30 /// any. Returns `None` if `version` is not a valid Rust version string.
35 /// use version_check::Version;
37 /// let version = Version::parse("1.18.0").unwrap();
38 /// assert!(version.exactly("1.18.0"));
40 /// let version = Version::parse("1.20.0-nightly").unwrap();
41 /// assert!(version.exactly("1.20.0"));
42 /// assert!(version.exactly("1.20.0-beta"));
44 /// let version = Version::parse("1.3").unwrap();
45 /// assert!(version.exactly("1.3.0"));
47 /// let version = Version::parse("1").unwrap();
48 /// assert!(version.exactly("1.0.0"));
50 /// assert!(Version::parse("one.two.three").is_none());
51 /// assert!(Version::parse("1.65536.2").is_none());
52 /// assert!(Version::parse("1. 2").is_none());
53 /// assert!(Version::parse("").is_none());
54 /// assert!(Version::parse("1.").is_none());
55 /// assert!(Version::parse("1.2.3.4").is_none());
57 pub fn parse(version: &str) -> Option<Version> { in parse() argument
58 let splits = version.split('-') in parse()
73 Some(Version::from_mmp(maj, min, patch)) in parse()
76 /// Creates a `Version` from `(major, minor, patch)` version components.
81 /// use version_check::Version;
83 /// assert!(Version::from_mmp(1, 35, 0).exactly("1.35.0"));
84 /// assert!(Version::from_mmp(1, 33, 0).exactly("1.33.0"));
85 /// assert!(Version::from_mmp(1, 35, 1).exactly("1.35.1"));
86 /// assert!(Version::from_mmp(1, 13, 2).exactly("1.13.2"));
88 pub fn from_mmp(major: u16, minor: u16, patch: u16) -> Version { in from_mmp() argument
89 Version(((major as u64) << 32) | ((minor as u64) << 16) | patch as u64) in from_mmp()
92 /// Returns the `(major, minor, patch)` version components of `self`.
97 /// use version_check::Version;
99 /// assert_eq!(Version::parse("1.35.0").unwrap().to_mmp(), (1, 35, 0));
100 /// assert_eq!(Version::parse("1.33.0").unwrap().to_mmp(), (1, 33, 0));
101 /// assert_eq!(Version::parse("1.35.1").unwrap().to_mmp(), (1, 35, 1));
102 /// assert_eq!(Version::parse("1.13.2").unwrap().to_mmp(), (1, 13, 2));
111 /// Returns `true` if `self` is greater than or equal to `version`.
113 /// If `version` is greater than `self`, or if `version` is not a valid Rust
114 /// version string, returns `false`.
119 /// use version_check::Version;
121 /// let version = Version::parse("1.35.0").unwrap();
123 /// assert!(version.at_least("1.33.0"));
124 /// assert!(version.at_least("1.35.0"));
125 /// assert!(version.at_least("1.13.2"));
127 /// assert!(!version.at_least("1.35.1"));
128 /// assert!(!version.at_least("1.55.0"));
130 /// let version = Version::parse("1.12.5").unwrap();
132 /// assert!(version.at_least("1.12.0"));
133 /// assert!(!version.at_least("1.35.0"));
135 pub fn at_least(&self, version: &str) -> bool { in at_least()
136 Version::parse(version) in at_least()
137 .map(|version| self >= &version) in at_least()
141 /// Returns `true` if `self` is less than or equal to `version`.
143 /// If `version` is less than `self`, or if `version` is not a valid Rust
144 /// version string, returns `false`.
149 /// use version_check::Version;
151 /// let version = Version::parse("1.35.0").unwrap();
153 /// assert!(version.at_most("1.35.1"));
154 /// assert!(version.at_most("1.55.0"));
155 /// assert!(version.at_most("1.35.0"));
157 /// assert!(!version.at_most("1.33.0"));
158 /// assert!(!version.at_most("1.13.2"));
160 pub fn at_most(&self, version: &str) -> bool { in at_most()
161 Version::parse(version) in at_most()
162 .map(|version| self <= &version) in at_most()
166 /// Returns `true` if `self` is exactly equal to `version`.
168 /// If `version` is not equal to `self`, or if `version` is not a valid Rust
169 /// version string, returns `false`.
174 /// use version_check::Version;
176 /// let version = Version::parse("1.35.0").unwrap();
178 /// assert!(version.exactly("1.35.0"));
180 /// assert!(!version.exactly("1.33.0"));
181 /// assert!(!version.exactly("1.35.1"));
182 /// assert!(!version.exactly("1.13.2"));
184 pub fn exactly(&self, version: &str) -> bool { in exactly()
185 Version::parse(version) in exactly()
186 .map(|version| self == &version) in exactly()
191 impl fmt::Display for Version { implementation
198 impl fmt::Debug for Version { implementation
201 write!(f, "Version({:?}, {:?})", self.0, self.to_mmp()) in fmt()
207 use super::Version;
213 assert_eq!(Version::parse($s), None);
216 assert_eq!(Version::parse($s).map(|v| v.to_mmp()), Some($mmp));
222 assert_eq!(Some(Version::from_mmp($x, $y, $z)), Version::parse($s));
272 let version = Version::parse("1.18.0").unwrap(); in test_comparisons() localVariable
273 assert!(version.exactly("1.18.0")); in test_comparisons()
274 assert!(version.at_least("1.12.0")); in test_comparisons()
275 assert!(version.at_least("1.12")); in test_comparisons()
276 assert!(version.at_least("1")); in test_comparisons()
277 assert!(version.at_most("1.18.1")); in test_comparisons()
278 assert!(!version.exactly("1.19.0")); in test_comparisons()
279 assert!(!version.exactly("1.18.1")); in test_comparisons()
281 let version = Version::parse("1.20.0-nightly").unwrap(); in test_comparisons() localVariable
282 assert!(version.exactly("1.20.0-beta")); in test_comparisons()
283 assert!(version.exactly("1.20.0-nightly")); in test_comparisons()
284 assert!(version.exactly("1.20.0")); in test_comparisons()
285 assert!(!version.exactly("1.19")); in test_comparisons()
287 let version = Version::parse("1.3").unwrap(); in test_comparisons() localVariable
288 assert!(version.exactly("1.3.0")); in test_comparisons()
289 assert!(version.exactly("1.3.0-stable")); in test_comparisons()
290 assert!(version.exactly("1.3")); in test_comparisons()
291 assert!(!version.exactly("1.5.0-stable")); in test_comparisons()
293 let version = Version::parse("1").unwrap(); in test_comparisons() localVariable
294 assert!(version.exactly("1.0.0")); in test_comparisons()
295 assert!(version.exactly("1.0")); in test_comparisons()
296 assert!(version.exactly("1")); in test_comparisons()
298 assert!(Version::parse("one.two.three").is_none()); in test_comparisons()
303 assert_eq!(Version::parse($s).unwrap().to_string(), $s);