#iterator #length #padding #padded

padded-iterator

An iterator that can be padded to a specified length

1 unstable release

0.1.0 Nov 20, 2023

#33 in #padding

MIT/Apache

10KB
199 lines

Padded Iterators

A Rust crate for an iterator that can be padded to a specified length.

License

This project is licensed under either of

at your option.


lib.rs:

This crate provides an iterator that pads the end of the iterator with a value up to a given length.

Examples:

use padded_iterator::PaddedIterBuilder;

let mut iter = PaddedIterBuilder::new()
    .iter(vec![1, 2, 3].into_iter())
    .length(5)
    .pad(0)
    .build()
    .unwrap();

assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(0));
assert_eq!(iter.next(), Some(0));
assert_eq!(iter.next(), None);
use padded_iterator::PaddedIter;

let mut iter = PaddedIter::from((vec![1, 2, 3].into_iter(), 5, 0));

assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(0));
assert_eq!(iter.next(), Some(0));
assert_eq!(iter.next(), None);

No runtime deps