Last active
August 29, 2015 14:02
-
-
Save bvssvni/7db83c8737d9996895c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub struct Per<A, B>(f64); | |
| impl<T> Per<u8, T> { | |
| pub fn bytes(num: f64) -> Per<u8, T> { | |
| Per(num) | |
| } | |
| pub fn kibi_bytes(num: f64) -> Per<u8, T> { | |
| Per(num * 1024.0) | |
| } | |
| } | |
| impl<T, U> Per<T, U> { | |
| pub fn new(num: f64) -> Per<T, U> { | |
| Per(num) | |
| } | |
| } | |
| impl<T, U, V> Div<Per<T, V>, Per<V, U>> for Per<T, U> { | |
| fn div(&self, rhs: &Per<T, V>) -> Per<V, U> { | |
| match (*self, *rhs) { | |
| (Per(a), Per(b)) => Per(a / b), | |
| } | |
| } | |
| } | |
| impl<T, U, V> Mul<Per<U, V>, Per<T, V>> for Per<T, U> { | |
| fn mul(&self, rhs: &Per<U, V>) -> Per<T, V> { | |
| match (*self, *rhs) { | |
| (Per(a), Per(b)) => Per(a * b), | |
| } | |
| } | |
| } | |
| impl<T, U> Add<Per<T, U>, Per<T, U>> for Per<T, U> { | |
| fn add(&self, rhs: &Per<T, U>) -> Per<T, U> { | |
| match (*self, *rhs) { | |
| (Per(a), Per(b)) => Per(a + b), | |
| } | |
| } | |
| } | |
| impl<T, U> Sub<Per<T, U>, Per<T, U>> for Per<T, U> { | |
| fn sub(&self, rhs: &Per<T, U>) -> Per<T, U> { | |
| match (*self, *rhs) { | |
| (Per(a), Per(b)) => Per(a - b), | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment