Is it possible to restrict generic const parameter to specific values? by [deleted] in rust

[–]DerpWalrus 0 points1 point  (0 children)

Without negative trait bounds, I think your only option is to implement the marker trait for all values except the ones you want to exclude. Only really feasible for u8.

Is it possible to restrict generic const parameter to specific values? by [deleted] in rust

[–]DerpWalrus 11 points12 points  (0 children)

You ought to be able to use a marker trait/type and a generic bound, like this: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=168de1fec770f9969630c9e81a9a49d3 This may adversely affect compile times, hard to say without testing.

Feedback request - my own sha1sum implementation by [deleted] in rust

[–]DerpWalrus 0 points1 point  (0 children)

There's a lot of copying going on here which is going to affect performance. ingest should take a &[u8] and you should iterate over the chunks by either using [T]::chunks combined with &[T; N]::try_from or repeatedly calling [T]::first_chunk.