From 5a7c44ed372e2754a8714f41c9d02303924a4b7b Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 8 Jul 2019 18:53:25 +1000 Subject: [PATCH] Add failing doc tests --- eth2/utils/ssz_types/src/bitfield.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/eth2/utils/ssz_types/src/bitfield.rs b/eth2/utils/ssz_types/src/bitfield.rs index 683fc67e11..e64f790dd4 100644 --- a/eth2/utils/ssz_types/src/bitfield.rs +++ b/eth2/utils/ssz_types/src/bitfield.rs @@ -29,6 +29,22 @@ impl BitfieldBehaviour for BitVector {} /// use with a `BitList` sets a type-level (i.e., compile-time) maximum length and `BitVector` /// provides a type-level fixed length. /// +/// ## Example +/// ``` +/// use ssz_types::{Bitfield, BitVector, BitList, typenum}; +/// +/// type BitList8 = Bitfield>; +/// +/// // The `N` type parameter specifies a maximum length. Creating a `BitList` with a larger +/// // capacity returns `None`. +/// assert!(BitList8::with_capacity(9).is_none()); +/// +/// let mut bitlist = BitList8::with_capacity(4); // `BitList` permits a capacity of less than the maximum. +/// assert!(bitlist.set(3, true).is_some()); // Setting inside the instantiation capacity is permitted. +/// assert!(bitlist.set(4, true).is_none()); // Setting outside that capacity is not. +/// +/// ``` +/// /// ## Note /// /// The internal representation of the bitfield is the same as that required by SSZ - the highest