You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is intended to be used like read_exact where you expect a certain number of bytes and any early EOF should be treated as an error (and the corresponding bytes simply dropped). If you need to handle early EOF then you should be using read instead of this.
Reacted by Josh Triplett, Johannes Dahlström and Tim Vergenz
@Amanieu Why does whether read_array can be overridden have any bearing on it working on dyn Read types?
Besides that, I don't think it absolutely needs to be final. For example, someone may want to eliminate the potential panic if they can guarantee correctness of read_buf_exact.
In order to keep Read dyn-compatible we would need to add where Self: Sized bounds to the method so it doesn't get included in the vtable. However it then becomes impossible to use this method with a dyn Read. If we want this method to be available on dyn Read then it must be a final fn, and that's not something we can do in the future in a backwards-compatible manner.
Activity
Implement `Read::read_array`
Rollup merge of rust-lang#148850 - joshtriplett:read-array, r=joboet
Rollup merge of rust-lang#148850 - joshtriplett:read-array, r=joboet
Rollup merge of rust-lang#148850 - joshtriplett:read-array, r=joboet
Rollup merge of rust-lang#148850 - joshtriplett:read-array, r=joboet
Rollup merge of rust-lang#148850 - joshtriplett:read-array, r=joboet
Rollup merge of rust-lang#148850 - joshtriplett:read-array, r=joboet
Unrolled build for #148850
lyphyser commentedon Nov 26, 2025
I think this should return an ArrayVec equivalent (in which case the caller would chain a try_into() to get a plain array if they want).
Currently, it throws away data if there is some data available but not enough to fill the array, which is not a good interface.
It would be even more general to take an ArrayVec by &mut reference, and even more general some trait that can take both a Vec and an ArrayVec.
Amanieu commentedon Nov 27, 2025
This is intended to be used like
read_exactwhere you expect a certain number of bytes and any early EOF should be treated as an error (and the corresponding bytes simply dropped). If you need to handle early EOF then you should be usingreadinstead of this.Implement `Read::read_array`
Rollup merge of rust-lang#148850 - joshtriplett:read-array, r=joboet
Amanieu commentedon Dec 9, 2025
This should only be stabilized as a
finalmethod as per rust-lang/rfcs#3678. This will allowread_arrayto work ondyn Readtypes.thaliaarchi commentedon Jun 26, 2026
@Amanieu Why does whether
read_arraycan be overridden have any bearing on it working ondyn Readtypes?Besides that, I don't think it absolutely needs to be
final. For example, someone may want to eliminate the potential panic if they can guarantee correctness ofread_buf_exact.Amanieu commentedon Jun 26, 2026
In order to keep
Readdyn-compatible we would need to addwhere Self: Sizedbounds to the method so it doesn't get included in the vtable. However it then becomes impossible to use this method with adyn Read. If we want this method to be available ondyn Readthen it must be afinal fn, and that's not something we can do in the future in a backwards-compatible manner.