refactor(headers): Use u16 based newtype for quality value
Using floating point numbers is problematic because comparison is inexact. They also take more space than integral numbers in this case. Add `FromPrimitve`, `ToPrimitive` and `Default` traits to quality newtype. Closes: #330 BREAKING_CHANGE: Replace f32 quality values in quality items with a Quality(u16) newtype. Valid values are from 0 to 1000.
This commit is contained in:
@@ -13,7 +13,7 @@ impl_list_header!(AcceptEncoding,
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use header::{Encoding, Header, QualityItem};
|
||||
use header::{Encoding, Header, qitem, Quality, QualityItem};
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -21,8 +21,8 @@ mod tests {
|
||||
fn test_parse_header() {
|
||||
let a: AcceptEncoding = Header::parse_header([b"gzip;q=1.0, identity; q=0.5".to_vec()].as_slice()).unwrap();
|
||||
let b = AcceptEncoding(vec![
|
||||
QualityItem{item: Encoding::Gzip, quality: 1f32},
|
||||
QualityItem{item: Encoding::Identity, quality: 0.5f32},
|
||||
qitem(Encoding::Gzip),
|
||||
QualityItem::new(Encoding::Identity, Quality(500)),
|
||||
]);
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user