Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AnthonyMikh opened this issue Oct 22, 2019 · 0 comments
Open

Comments

@AnthonyMikh
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant