Commit cec9fed7 authored by Stefan Schindler's avatar Stefan Schindler
Browse files

Implement - for ByteUnit

parent 3eec1dbc
...@@ -206,17 +206,19 @@ impl std::ops::AddAssign for ByteUnit { ...@@ -206,17 +206,19 @@ impl std::ops::AddAssign for ByteUnit {
} }
} }
} }
impl std::ops::Sub for ByteUnit {
type Output = ByteUnit;
fn sub(self, other: Self) -> Self {
#[derive(Debug,PartialEq,Eq)] match self {
enum DiskState { Byte(l) => match other {
Detected, Byte(r) => Byte(l - r),
QueueForWhipe, something_else => self - something_else.to_byte(),
Whiping{ progress: ByteUnit, per_second: ByteUnit }, },
Whiped, something_else => something_else.to_byte() - other,
WhipeFailed, }
}
} }
use DiskState::*;
impl Display for ByteUnit { impl Display for ByteUnit {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
...@@ -449,4 +451,22 @@ mod test { ...@@ -449,4 +451,22 @@ mod test {
four += Byte(2); four += Byte(2);
assert_eq!(Byte(2 + 2048), four); assert_eq!(Byte(2 + 2048), four);
} }
#[test]
fn sub_bytes() {
assert_eq!(Byte(0), Byte(2) - Byte(2));
}
#[test]
fn sub_kilobytes() {
assert_eq!(KiloByte(0), KiloByte(2) - KiloByte(2));
}
#[test]
fn sub_bytes_mixed_up() {
assert_eq!(Byte(2), Byte(2048 + 2) - KiloByte(2));
}
#[test]
fn sub_bytes_mixed_down() {
assert_eq!(Byte(2048 - 2), KiloByte(2) - Byte(2));
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment