@@ -43,34 +43,19 @@ impl SemVer {
43
43
major,
44
44
minor,
45
45
patch,
46
- pre : String :: default ( ) ,
47
- }
48
- }
49
-
50
- pub fn bump_major ( & self ) -> SemVer {
51
- SemVer {
52
- major : self . major + 1 ,
53
- minor : 0 ,
54
- patch : 0 ,
55
- pre : String :: default ( ) ,
56
- }
57
- }
58
-
59
- pub fn bump_minor ( & self ) -> SemVer {
60
- SemVer {
61
- major : self . major ,
62
- minor : self . minor + 1 ,
63
- patch : 0 ,
64
- pre : String :: default ( ) ,
46
+ pre : String :: new ( ) ,
65
47
}
66
48
}
49
+ }
67
50
68
- pub fn next_incompatible ( & self ) -> SemVer {
69
- // TODO: should we panic or something if pre is non-empty?
70
- if self . major == 0 {
71
- self . bump_minor ( )
72
- } else {
73
- self . bump_major ( )
51
+ impl SemVerPrefix {
52
+ pub fn matches ( & self , v : & SemVer ) -> bool {
53
+ match ( self . minor , self . patch ) {
54
+ ( None , _) => v. major == self . major ,
55
+ ( Some ( minor) , None ) => v. major == self . major && v. minor >= minor,
56
+ ( Some ( minor) , Some ( patch) ) => {
57
+ v. major == self . major && v. minor == minor && v. patch >= patch
58
+ }
74
59
}
75
60
}
76
61
}
@@ -113,8 +98,8 @@ impl From<SemVer> for FullSemVer {
113
98
// information is sometimes relevant for comparing version requirements (e.g.,
114
99
// "1.3.0" matches the requirement "1.2" but it doesn't match the requirement
115
100
// "1.2.0").
116
- impl From < PartialSemVer > for SemVer {
117
- fn from ( psv : PartialSemVer ) -> Self {
101
+ impl From < SemVerPrefix > for SemVer {
102
+ fn from ( psv : SemVerPrefix ) -> Self {
118
103
Self {
119
104
major : psv. major ,
120
105
minor : psv. minor . unwrap_or ( 0 ) ,
@@ -166,13 +151,13 @@ impl std::fmt::Display for SemVer {
166
151
#[ derive(
167
152
Clone , Debug , Eq , PartialEq , Ord , PartialOrd , Hash , serde:: Serialize , serde:: Deserialize ,
168
153
) ]
169
- pub struct PartialSemVer {
154
+ pub struct SemVerPrefix {
170
155
pub major : u64 ,
171
156
pub minor : Option < u64 > ,
172
157
pub patch : Option < u64 > ,
173
158
}
174
159
175
- impl PartialSemVer {
160
+ impl SemVerPrefix {
176
161
pub fn major_minor ( major : u64 , minor : u64 ) -> Self {
177
162
Self {
178
163
major,
@@ -192,7 +177,7 @@ pub enum PartialSemVerParseError {
192
177
Num ( #[ from] ParseIntError ) ,
193
178
}
194
179
195
- impl FromStr for PartialSemVer {
180
+ impl FromStr for SemVerPrefix {
196
181
type Err = PartialSemVerParseError ;
197
182
198
183
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
@@ -215,7 +200,7 @@ impl FromStr for PartialSemVer {
215
200
}
216
201
}
217
202
218
- impl std:: fmt:: Display for PartialSemVer {
203
+ impl std:: fmt:: Display for SemVerPrefix {
219
204
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
220
205
match ( self . minor , self . patch ) {
221
206
( None , _) => {
0 commit comments