Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use consts::SECTOR_SIZE;

use std::fmt;
use std::fmt::Display;
use std::ops::{Div, Mul, Rem};
use std::iter::Sum;
use std::ops::{Div, Mul, Rem, Add};

use serde;
// macros for unsigned operations on Sectors and Bytes
Expand Down Expand Up @@ -94,6 +95,12 @@ impl Bytes {
}
}

impl Sum for Bytes {
fn sum<I: Iterator<Item = Bytes>>(iter: I) -> Bytes {
iter.fold(Bytes(0), Add::add)
}
}

unsigned_mul!(u64, Bytes);
unsigned_mul!(u32, Bytes);
unsigned_mul!(u16, Bytes);
Expand Down Expand Up @@ -141,6 +148,12 @@ impl serde::Deserialize for Sectors {
}
}

impl Sum for Sectors {
fn sum<I: Iterator<Item = Sectors>>(iter: I) -> Sectors {
iter.fold(Sectors(0), Add::add)
}
}

unsigned_div!(u64, Sectors);
unsigned_div!(u32, Sectors);
unsigned_div!(u16, Sectors);
Expand Down