rust-cuckoofilter icon indicating copy to clipboard operation
rust-cuckoofilter copied to clipboard

`impl<'a> From<&'a [u8]> for Bucket` doesn't adhere Rust conventions

Open AnthonyMikh opened this issue 5 years ago • 0 comments

The following code is problematic:

https://github.com/seiflotfy/rust-cuckoofilter/blob/c7fea791f1c21deda02a263e69f0fec428e10c61/src/bucket.rs#L96-L105

This code can panic for two reasons: 1) fingerprints contains more than BUCKET_SIZE chunks; 2) fingerprints can't be divided evenly into FINGERPRINT_SIZEd chunks (slice_copy forwards to [T]::copy_from_slice which panics if slices have different lengths). However, the documentation for From trait explicitly claims that conversions defined through From::from should be infallible.

The correct solution in this case would be redo this code into TryFrom impl. Of course, this would break backwards compatibility.

AnthonyMikh avatar Oct 22 '19 10:10 AnthonyMikh