Skip to content

Commit 4e48d9a

Browse files
authored
Add new method repeat_full to VariableList (#62)
1 parent 827ffba commit 4e48d9a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/variable_list.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ impl<T, N: Unsigned> VariableList<T, N> {
106106
}
107107
}
108108

109+
/// Creates a full list with the given element repeated.
110+
pub fn repeat_full(elem: T) -> Self
111+
where
112+
T: Clone,
113+
{
114+
Self {
115+
vec: vec![elem; N::to_usize()],
116+
_phantom: PhantomData,
117+
}
118+
}
119+
109120
/// Returns the number of values presently in `self`.
110121
pub fn len(&self) -> usize {
111122
self.vec.len()
@@ -386,6 +397,13 @@ mod test {
386397
assert!(fixed.is_ok());
387398
}
388399

400+
#[test]
401+
fn repeat_full() {
402+
let manual_list = VariableList::<u64, U5>::new(vec![42; 5]).unwrap();
403+
let repeat_list = VariableList::<u64, U5>::repeat_full(42);
404+
assert_eq!(manual_list, repeat_list);
405+
}
406+
389407
#[test]
390408
fn indexing() {
391409
let vec = vec![1, 2];

0 commit comments

Comments
 (0)