You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Quantity is a representation of a number with a suffix / format.
35
49
///
36
50
/// This type makes it possible to parse Kubernetes quantity strings like '12Ki', '2M, '1.5e2', or
@@ -208,6 +222,28 @@ impl Quantity {
208
222
}
209
223
}
210
224
225
+
pubfnscale_to_non_zero(self) -> Self{
226
+
if !self.value.between(-1.0,1.0){
227
+
returnself;
228
+
}
229
+
230
+
letmut this = self;
231
+
232
+
whileletSome(suffix) = this.suffix.scale_down(){
233
+
this = self.scale_to(suffix);
234
+
if this.value.between(-1.0,1.0){
235
+
continue;
236
+
}else{
237
+
return this;
238
+
}
239
+
}
240
+
241
+
Self{
242
+
value:1.0,
243
+
suffix: this.suffix,
244
+
}
245
+
}
246
+
211
247
/// Either sets the suffix of `self` to `rhs` or scales `rhs` if `self` has a value other than
212
248
/// zero.
213
249
///
@@ -228,46 +264,54 @@ impl Quantity {
228
264
}
229
265
}
230
266
267
+
traitFloatExt:PartialOrd + Sized{
268
+
fnbetween(self,start:Self,end:Self) -> bool{
269
+
self > start && self < end
270
+
}
271
+
}
272
+
273
+
implFloatExtforf64{}
274
+
231
275
#[cfg(test)]
232
276
mod test {
233
277
usesuper::*;
234
278
use rstest::rstest;
235
279
280
+
// See https://github.com/kubernetes/apimachinery/blob/3e8e52d6a1259ada73f63c1c7d1fad39d4ba9fb4/pkg/api/resource/quantity_test.go#L276-L287
// See https://github.com/kubernetes/apimachinery/blob/3e8e52d6a1259ada73f63c1c7d1fad39d4ba9fb4/pkg/api/resource/quantity_test.go#L289
0 commit comments