Skip to content

Commit 882d263

Browse files
authored
Merge pull request #34 from johnsonw/johnsonw/integrate-arbitrary-feature
Integrate Arbitrary Feature
2 parents cb77498 + f500405 commit 882d263

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ keywords = ["byte", "byte-size", "utility", "human-readable", "format"]
1212
license = "Apache-2.0"
1313

1414
[dependencies]
15+
arbitrary = { version = "1.3.0", optional = true }
1516
serde = { version = "1.0.185", optional = true }
1617

1718
[dev-dependencies]
@@ -20,5 +21,6 @@ serde_json = "1.0.105"
2021
toml = "0.7.6"
2122

2223
[features]
24+
arbitrary = ["dep:arbitrary"]
2325
default = []
2426
serde = ["dep:serde"]

src/lib.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
3030
mod parse;
3131

32+
#[cfg(feature = "arbitrary")]
33+
extern crate arbitrary;
3234
#[cfg(feature = "serde")]
3335
extern crate serde;
3436
#[cfg(feature = "serde")]
@@ -110,6 +112,7 @@ pub fn pib<V: Into<u64>>(size: V) -> u64 {
110112

111113
/// Byte size representation
112114
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
115+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
113116
pub struct ByteSize(pub u64);
114117

115118
impl ByteSize {
@@ -208,7 +211,7 @@ pub fn to_string(bytes: u64, si_prefix: bool) -> String {
208211
}
209212

210213
impl Display for ByteSize {
211-
fn fmt(&self, f: &mut Formatter) ->fmt::Result {
214+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
212215
f.pad(&to_string(self.0, false))
213216
}
214217
}
@@ -261,7 +264,9 @@ impl AddAssign<ByteSize> for ByteSize {
261264
}
262265

263266
impl<T> Add<T> for ByteSize
264-
where T: Into<u64> {
267+
where
268+
T: Into<u64>,
269+
{
265270
type Output = ByteSize;
266271
#[inline(always)]
267272
fn add(self, rhs: T) -> ByteSize {
@@ -270,15 +275,19 @@ impl<T> Add<T> for ByteSize
270275
}
271276

272277
impl<T> AddAssign<T> for ByteSize
273-
where T: Into<u64> {
278+
where
279+
T: Into<u64>,
280+
{
274281
#[inline(always)]
275282
fn add_assign(&mut self, rhs: T) {
276283
self.0 += rhs.into() as u64;
277284
}
278285
}
279286

280287
impl<T> Mul<T> for ByteSize
281-
where T: Into<u64> {
288+
where
289+
T: Into<u64>,
290+
{
282291
type Output = ByteSize;
283292
#[inline(always)]
284293
fn mul(self, rhs: T) -> ByteSize {
@@ -287,7 +296,9 @@ impl<T> Mul<T> for ByteSize
287296
}
288297

289298
impl<T> MulAssign<T> for ByteSize
290-
where T: Into<u64> {
299+
where
300+
T: Into<u64>,
301+
{
291302
#[inline(always)]
292303
fn mul_assign(&mut self, rhs: T) {
293304
self.0 *= rhs.into() as u64;

0 commit comments

Comments
 (0)