Get rid of value_in
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Peter · committed by David Peter · parent 6b4e9eb · Browse files · 1 file·+7 added−29 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+7 added−29 removed
- other:+7 added−29 removed
Provenance
- Commit
3d9e230- Tree
8cbd4b5- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
David Peter <mail@david-peter.de>- Parent
6b4e9eb
1 file changed+7 added−29 removed
modified:src/quantity/mod.rs+7 added-29 removed
24 unmodified lines25 fn zero() -> Time {26 Time::new::<second>(0.0)27 }28 29- fn value_in<U>(&self, u: U) -> f6430- where31- U: si::time::Unit + Conversion<f64, T = f64>;32-29 fn suitable_unit(&self) -> TimeUnit;30 31 fn format(&self, u: TimeUnit, precision: Option<usize>) -> String;32 fn format_auto(&self, time_unit: Option<TimeUnit>) -> String;33 fn format_value_auto(&self, time_unit: Option<TimeUnit>) -> String;34 }35 36 impl TimeQuantity for Time {41- fn value_in<U>(&self, _u: U) -> f6442- where43- U: si::time::Unit + Conversion<f64, T = f64>,44- {45- self.get::<U>()46- }47-37 fn suitable_unit(&self) -> TimeUnit {38 if *self < Time::new::<millisecond>(1.0) {39 TimeUnit::MicroSecond40 } else if *self < Time::new::<second>(1.0) {40 unmodified lines81 fn zero() -> Information {82 Information::new::<byte>(0.)83 }84 96- fn value_in<U>(&self, u: U) -> f6497- where98- U: si::information::Unit + Conversion<f64, T = f64>;99-85 fn to_string<U>(&self, u: U) -> String86 where87 U: si::information::Unit + Conversion<f64, T = f64>;88 }89 90 impl InformationQuantity for Information {106- fn value_in<U>(&self, _u: U) -> f64107- where108- U: si::information::Unit + Conversion<f64, T = f64>,109- {110- self.get::<U>()111- }112-91 fn to_string<U>(&self, u: U) -> String92 where93 U: si::information::Unit + Conversion<f64, T = f64>,94 {10 unmodified lines105 }106 107 impl UnsafeRawValue for Time {108 fn unsafe_raw_value(&self) -> f64 {131- self.value_in(second)109+ self.get::<second>()110 }111 112 fn unsafe_from_raw_value(value: f64) -> Self {113 Time::new::<second>(value)1 unmodified line115 }116 117 impl UnsafeRawValue for Information {118 fn unsafe_raw_value(&self) -> f64 {141- self.value_in(byte)119+ self.get::<byte>()120 }121 122 fn unsafe_from_raw_value(value: f64) -> Self {123 Information::new::<byte>(value)47 unmodified lines171 172 #[test]173 fn test_time() {174 let time = Time::new::<millisecond>(123.4);197- assert_eq!(time.value_in(millisecond), 123.4);175+ assert_eq!(time.get::<millisecond>(), 123.4);176 199- let time_s = time.value_in(second);177+ let time_s = time.get::<second>();178 approx::assert_relative_eq!(time_s, 0.1234);179 202- let time_us = time.value_in(microsecond);180+ let time_us = time.get::<microsecond>();181 approx::assert_relative_eq!(time_us, 123400.0);182 }183 184 #[test]185 fn test_information() {186 let information = Information::new::<kibibyte>(8.);209- assert_eq!(information.value_in(byte), 8192.);187+ assert_eq!(information.get::<byte>(), 8192.);188 211- let information_kib = information.value_in(kibibyte);189+ let information_kib = information.get::<kibibyte>();190 assert_eq!(information_kib, 8.);191 }192 193 #[test]54 unmodified lines