Rust beginner notes & questions

Note that you borrow self mutably and then (presumably) return slice to a buffer inside self. This will not work nicely, as you'll have to drop &[Self::Data] before calling peek again, otherwise borrow checker will rightfully yell at you. Borrow regions could probably help here, but your proposal has another problem. How do you think it will work with e.g. buffered file IO? Also it will not work if underlying buffer is not owned without GAT.

No one forbids you from prototyping such zero-copy Read trait in a separate crate. Unfortunately you will not be able to write impl<T: ZeroCopyRead> Read for T { .. } (I really hope we will be able to do it in future), but it's not a huge problem. If your design will be good enough and will find enought traction, then the next step could be an RFC with proposal of this trait addition to std. But as you can see you'll probably encounter a lot of problems and blockers. I agree with @BurntSushi that it's not productive to discuss such hand-wavy proposals, with arguably weak motivation.

2 Likes