I am trying to simplify new
function of my generic struct. Right now, I can create a new struct by using
let data: Vec<u8> = Vec::new();
ColumnIterator::new(
data.as_slice(),
7,
data.as_slice().iter().step_by(7)
);
struct ColumnIterator<'a, T: Iterator<Item = &'a u8>> {
data: &'a [u8],
col: usize,
internal: T,
}
impl<'a, T: Iterator<Item = &'a u8>> ColumnIterator<'a, T> {
fn new(data: &'a [u8], col: usize, internal: T) -> Self {
ColumnIterator {
data,
col,
internal,
}
}
}
However, since ColumnIterator
has all information to create the internal
, and for better API, I was trying to do this:
fn new(data: &'a [u8], col: usize) -> Self {
ColumnIterator {
data,
col,
internal: data.iter().step_by(col)
}
}
}
which gives me expected type parameter, found struct std::iter::StepBy
error
How do I construct a concrete type to initialize a generic field of an struct
?
Link to Playground