1 # use std::{cmp, hash};
2 # #[derive(PartialEq, Hash)]
3 # struct Identifier;
4 pub struct Version {
5     /// The major version.
6     pub major: u64,
7     /// The minor version.
8     pub minor: u64,
9     /// The patch version.
10     pub patch: u64,
11     /// The pre-release version identifier.
12     pub pre: Vec<Identifier>,
13     /// The build metadata, ignored when
14     /// determining version precedence.
15     pub build: Vec<Identifier>,
16 }
17 
18 impl cmp::PartialEq for Version {
19     #[inline]
eq(&self, other: &Version) -> bool20     fn eq(&self, other: &Version) -> bool {
21         // We should ignore build metadata
22         // here, otherwise versions v1 and
23         // v2 can exist such that !(v1 < v2)
24         // && !(v1 > v2) && v1 != v2, which
25         // violate strict total ordering rules.
26         self.major == other.major &&
27         self.minor == other.minor &&
28         self.patch == other.patch &&
29         self.pre == other.pre
30     }
31 }
32 
33 impl hash::Hash for Version {
hash<H: hash::Hasher>(&self, into: &mut H)34     fn hash<H: hash::Hasher>(&self, into: &mut H) {
35         self.major.hash(into);
36         self.minor.hash(into);
37         self.patch.hash(into);
38         self.pre.hash(into);
39     }
40 }