Skip to content
Myr

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

1 file+7 added−29 removed

modified:src/quantity/mod.rs+7 added-29 removed
24 unmodified lines
25 fn zero() -> Time {26 Time::new::<second>(0.0)27 }2829 fn value_in<U>(&self, u: U) -> f6430 where31 U: si::time::Unit + Conversion<f64, T = f64>;3229 fn suitable_unit(&self) -> TimeUnit;3031 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}3536impl 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 }4737 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 lines
81 fn zero() -> Information {82 Information::new::<byte>(0.)83 }8496 fn value_in<U>(&self, u: U) -> f6497 where98 U: si::information::Unit + Conversion<f64, T = f64>;9985 fn to_string<U>(&self, u: U) -> String86 where87 U: si::information::Unit + Conversion<f64, T = f64>;88}8990impl 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 }11291 fn to_string<U>(&self, u: U) -> String92 where93 U: si::information::Unit + Conversion<f64, T = f64>,94 {
10 unmodified lines
105}106107impl UnsafeRawValue for Time {108 fn unsafe_raw_value(&self) -> f64 {131 self.value_in(second)109 self.get::<second>()110 }111112 fn unsafe_from_raw_value(value: f64) -> Self {113 Time::new::<second>(value)
1 unmodified line
115}116117impl UnsafeRawValue for Information {118 fn unsafe_raw_value(&self) -> f64 {141 self.value_in(byte)119 self.get::<byte>()120 }121122 fn unsafe_from_raw_value(value: f64) -> Self {123 Information::new::<byte>(value)
47 unmodified lines
171172#[test]173fn 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);176199 let time_s = time.value_in(second);177 let time_s = time.get::<second>();178 approx::assert_relative_eq!(time_s, 0.1234);179202 let time_us = time.value_in(microsecond);180 let time_us = time.get::<microsecond>();181 approx::assert_relative_eq!(time_us, 123400.0);182}183184#[test]185fn test_information() {186 let information = Information::new::<kibibyte>(8.);209 assert_eq!(information.value_in(byte), 8192.);187 assert_eq!(information.get::<byte>(), 8192.);188211 let information_kib = information.value_in(kibibyte);189 let information_kib = information.get::<kibibyte>();190 assert_eq!(information_kib, 8.);191}192193#[test]
54 unmodified lines