Interface for CRC32 checksum (or similar digest)

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
    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 Items 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 {

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?

If the user is trying to pass an iterator that returns a reference, they can just call copied to get an iterator that adapts it to returning u8s

1 Like

Thank you both!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.