mrhooray / crc-rs

Rust implementation of CRC(16, 32, 64) with support of various standards

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reduce duplicate code

kitlith opened this issue · comments

Much of the code between crc32 and crc64 is identical, barring the different types.

This is most obvious in the table generation code in src/util.rs, where the implementations are side-by-side, but can also be seen in most, if not all of the code in the crc32 and crc64 modules.

I feel like this could be fixed with a function with a generic argument, but that would leave the question of, say, how to implement a CRC-5 or CRC-24... maybe some sort of n-bit integer type? BigInt except you specify the number of bits? That would probably be in the scope of another crate entirely, though, so long as the trait bounds were permissive enough.

multiples of 8 bits should be good enough. you're welcome to give it a try and see what interface and implementation look like

Alright, I've got something that will compile: https://gist.github.com/kitling/2f7f38e485449fc7b7fe047a62019581

Remaining is getting backwards compatibility with the existing API. Unfortunately, it doesn't seem as simple as aliasing the generics to specifics, as this doesn't seem to exist at the very least for functions.