@@ -222,7 +222,7 @@ pub struct PathItem {
222
222
pub struct Margins {
223
223
#[ schema( inline) ]
224
224
pub boundaries : Vec < NonBlankString > ,
225
- #[ derivative( Default ( value = "vec![MarginValue::Zero ]" ) ) ]
225
+ #[ derivative( Default ( value = "vec![MarginValue::None ]" ) ) ]
226
226
/// The values of the margins. Must contains one more element than the boundaries
227
227
/// Can be a percentage `X%`, a time in minutes per kilometer `Xmin/km` or `0`
228
228
#[ schema( value_type = Vec <String >, example = json!( [ "0" , "5%" , "2min/km" ] ) ) ]
@@ -253,7 +253,7 @@ impl<'de> Deserialize<'de> for Margins {
253
253
#[ derive( Debug , Copy , Clone , Default , PartialEq ) ]
254
254
pub enum MarginValue {
255
255
#[ default]
256
- Zero ,
256
+ None ,
257
257
Percentage ( f64 ) ,
258
258
MinPerKm ( f64 ) ,
259
259
}
@@ -264,8 +264,8 @@ impl<'de> Deserialize<'de> for MarginValue {
264
264
D : serde:: Deserializer < ' de > ,
265
265
{
266
266
let value = String :: deserialize ( deserializer) ?;
267
- if value == "0 " {
268
- return Ok ( Self :: Zero ) ;
267
+ if value. to_lowercase ( ) == "none " {
268
+ return Ok ( Self :: None ) ;
269
269
}
270
270
if value. ends_with ( '%' ) {
271
271
let float_value = f64:: from_str ( value[ 0 ..value. len ( ) - 1 ] . trim ( ) ) . map_err ( |_| {
@@ -274,15 +274,12 @@ impl<'de> Deserialize<'de> for MarginValue {
274
274
& "a valid float" ,
275
275
)
276
276
} ) ?;
277
- if float_value < 0.0 {
277
+ if float_value <= 0.0 {
278
278
return Err ( serde:: de:: Error :: invalid_value (
279
279
serde:: de:: Unexpected :: Str ( & value) ,
280
- & "a positive float " ,
280
+ & "a strictly positive number " ,
281
281
) ) ;
282
282
}
283
- if float_value == 0. {
284
- return Ok ( Self :: Zero ) ;
285
- }
286
283
return Ok ( Self :: Percentage ( float_value) ) ;
287
284
}
288
285
if value. ends_with ( "min/km" ) {
@@ -293,15 +290,12 @@ impl<'de> Deserialize<'de> for MarginValue {
293
290
& "a valid float" ,
294
291
)
295
292
} ) ?;
296
- if float_value < 0.0 {
293
+ if float_value <= 0.0 {
297
294
return Err ( serde:: de:: Error :: invalid_value (
298
295
serde:: de:: Unexpected :: Str ( & value) ,
299
- & "a positive float" ,
296
+ & "a strictly positive float" ,
300
297
) ) ;
301
298
}
302
- if float_value == 0. {
303
- return Ok ( Self :: Zero ) ;
304
- }
305
299
return Ok ( Self :: MinPerKm ( float_value) ) ;
306
300
}
307
301
Err ( serde:: de:: Error :: custom ( "Margin type not recognized" ) )
@@ -314,7 +308,7 @@ impl Serialize for MarginValue {
314
308
S : serde:: Serializer ,
315
309
{
316
310
match self {
317
- MarginValue :: Zero => serializer. serialize_str ( "0 " ) ,
311
+ MarginValue :: None => serializer. serialize_str ( "none " ) ,
318
312
MarginValue :: Percentage ( value) => serializer. serialize_str ( & format ! ( "{}%" , value) ) ,
319
313
MarginValue :: MinPerKm ( value) => serializer. serialize_str ( & format ! ( "{}min/km" , value) ) ,
320
314
}
@@ -349,12 +343,8 @@ mod tests {
349
343
/// Test that the `MarginValue` enum can be deserialized from a string
350
344
#[ test]
351
345
fn deserialize_margin_value ( ) {
352
- let zero: MarginValue = from_str ( r#""0""# ) . unwrap ( ) ;
353
- assert_eq ! ( zero, MarginValue :: Zero ) ;
354
- let percentage: MarginValue = from_str ( r#""0%""# ) . unwrap ( ) ;
355
- assert_eq ! ( percentage, MarginValue :: Zero ) ;
356
- let min_per_km: MarginValue = from_str ( r#""0min/km""# ) . unwrap ( ) ;
357
- assert_eq ! ( min_per_km, MarginValue :: Zero ) ;
346
+ let none: MarginValue = from_str ( r#""none""# ) . unwrap ( ) ;
347
+ assert_eq ! ( none, MarginValue :: None ) ;
358
348
359
349
let percentage: MarginValue = from_str ( r#""10%""# ) . unwrap ( ) ;
360
350
assert_eq ! ( percentage, MarginValue :: Percentage ( 10.0 ) ) ;
@@ -374,8 +364,8 @@ mod tests {
374
364
/// Test that the `MarginValue` enum can be serialized to a string
375
365
#[ test]
376
366
fn serialize_margin_value ( ) {
377
- let zero = to_string ( & MarginValue :: Zero ) . unwrap ( ) ;
378
- assert_eq ! ( zero , r#""0 ""# ) ;
367
+ let none = to_string ( & MarginValue :: None ) . unwrap ( ) ;
368
+ assert_eq ! ( none , r#""none ""# ) ;
379
369
380
370
let percentage = to_string ( & MarginValue :: Percentage ( 10.0 ) ) . unwrap ( ) ;
381
371
assert_eq ! ( percentage, r#""10%""# ) ;
0 commit comments