diff --git a/src/types.rs b/src/types.rs index 8a6db33d..265617e9 100644 --- a/src/types.rs +++ b/src/types.rs @@ -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 @@ -94,6 +95,12 @@ impl Bytes { } } +impl Sum for Bytes { + fn sum>(iter: I) -> Bytes { + iter.fold(Bytes(0), Add::add) + } +} + unsigned_mul!(u64, Bytes); unsigned_mul!(u32, Bytes); unsigned_mul!(u16, Bytes); @@ -141,6 +148,12 @@ impl serde::Deserialize for Sectors { } } +impl Sum for Sectors { + fn sum>(iter: I) -> Sectors { + iter.fold(Sectors(0), Add::add) + } +} + unsigned_div!(u64, Sectors); unsigned_div!(u32, Sectors); unsigned_div!(u16, Sectors);