Hacker News new | ask | show | jobs
by steveklabnik 2043 days ago
You maybe could write something like this:

  pub struct Fifo<T: AsMut<[u8]>> {
and then back it with an array. I learned this trick from whitequark.

(Though maybe if you want something other than a slice of bytes, this gets harder... I've used this trick for ringbuffers/mmio only, personally, so YMMV.)

That being said real const generics will make this way nicer, eventually.

2 comments

I wasn't aware of this trick, thank you for that. I guess if I have to implement another FIFO before const generics land I'll have an opportunity to try it out...