Skip to content

Commit 06342e0

Browse files
committed
Add new method repeat_full to VariableList
1 parent dd6ac18 commit 06342e0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/variable_list.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ impl<T, N: Unsigned> VariableList<T, N> {
103103
}
104104
}
105105

106+
/// Creates a full list with the given element repeated.
107+
pub fn repeat_full(elem: T) -> Self
108+
where
109+
T: Clone,
110+
{
111+
Self {
112+
vec: vec![elem; N::to_usize()],
113+
_phantom: PhantomData,
114+
}
115+
}
116+
106117
/// Returns the number of values presently in `self`.
107118
pub fn len(&self) -> usize {
108119
self.vec.len()
@@ -383,6 +394,13 @@ mod test {
383394
assert!(fixed.is_ok());
384395
}
385396

397+
#[test]
398+
fn repeat_full() {
399+
let manual_list = VariableList::<u64, U5>::new(vec![42; 5]).unwrap();
400+
let repeat_list = VariableList::<u64, U5>::repeat_full(42);
401+
assert_eq!(manual_list, repeat_list);
402+
}
403+
386404
#[test]
387405
fn indexing() {
388406
let vec = vec![1, 2];

0 commit comments

Comments
 (0)