I'm trying to decide what the best interface is for a CRC32 checksum function. The signature in my current implementation looks like this:
pub fn checksum<I>(data: I) -> u32
where
I: IntoIterator<Item = u8>,
{
// ...
}
I'd like the function to be useful in a variety of settings, and ideally be callable with a Vec<u8>
, or &[u8]
, for instance. Unfortunately it's a little rigid at the moment: in particular, it won't accept arguments whose Item
s are &u8
(instead of u8
).
I thought there would be a From
implementation like this:
impl<T> From<&T> for T
where T: Copy
{
fn from(value: &T) -> T {
*value
}
}
which would let me bound I
with an Item
type that's Into<u8>
, but I don't see that trait implementation anywhere (probably for a good reason that I haven't thought of).
Is there a better choice for the signature here, or am I on the right track?