Open benhall-7 opened 2 years ago
Is there a reason why we can't make the existing update
function const
?
Is there a reason why we can't make the existing update function const?
This is because Rust doesn't allow &mut in const fn functions yet. The tracking issue for it is here: https://github.com/rust-lang/rust/issues/57349
Sorry for the delayed response, but wdyt about making Crc::update
public instead? Seems like exposing a single low-level API would address a lot of the edge cases without overburdening the high-level APIs.
EDIT: Actually, just update
wouldn't be enough, finalize
would also have to be exposed.
So for context, I'm working on a library for a special type of hash which involves a CRC32, but the implementation takes every character and makes it lowercase (ascii_lowercase) before it's hashed. Since this is a const fn, I'm not able to create a new allocations for the lowercased version. I've tried const generics, but that requires always knowing the input length at compile time, which is too restrictive. I've found a way to do this, by adding a const fn version of the update function in Digest, which I've implemented in this PR. Here's an example using it:
This is kind of an undesirable way to calculate the hash anyway, so if we can find some other way to write this, that would be cool too