Skip to content

Commit db04102

Browse files
committed
Add Arbitrary to Weight
1 parent 5d4f871 commit db04102

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

units/src/weight.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use core::fmt;
66
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
77

8+
#[cfg(feature = "arbitrary")]
9+
use arbitrary::{Arbitrary, Unstructured};
810
#[cfg(feature = "serde")]
911
use serde::{Deserialize, Serialize};
1012

@@ -338,3 +340,11 @@ impl<'a> core::iter::Sum<&'a Weight> for Weight {
338340
}
339341

340342
crate::impl_parse_str_from_int_infallible!(Weight, u64, from_wu);
343+
344+
#[cfg(feature = "arbitrary")]
345+
impl<'a> Arbitrary<'a> for Weight {
346+
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
347+
let w = u64::arbitrary(u)?;
348+
Ok(Weight(w))
349+
}
350+
}

0 commit comments

Comments
 (0)