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
with the idea "This should throw an error in case bytes.len() will be larger than self.capacity() - offset.". The main issue with this is it means our bytes buffer will always need to be "self.capacity() - offset" which would be needlessly wasteful for a vector to be resized every time it reaches the end of a file or one would need to have a precisely sized buffer. This prevents more usable patters in embedded such as:
while !file.is_eof(){letmut buffer:[u8;16] = [0;16];let characters_parsed = file.read(&mut buffer)?;
serialize_vec.extend_from_slice(&buffer[..characters_parsed]);}
This allows for the looping read of a fixed size buffer in a manner that extends a vector if a large amount of information needs to be collected and read at once (such as in the case of serialization and deserialization). For no-alloc this also allows a fixed size buffer to be used to read some arbitrary storage. I think that for embedded work this is far more typical interface and if the usize isn't needed by some implementations it can be dropped whereas without this implementation some storage implementations on some hardware peripherals wont work.
An alternative could be a read_buffer method or a separate buffer storage trait for no-alloc implementation, though that might add more complexity than desired especially if trying to reach the greatest common denominator.
Presently the read trait is:
with the idea "This should throw an error in case bytes.len() will be larger than self.capacity() - offset.". The main issue with this is it means our bytes buffer will always need to be "self.capacity() - offset" which would be needlessly wasteful for a vector to be resized every time it reaches the end of a file or one would need to have a precisely sized buffer. This prevents more usable patters in embedded such as:
This allows for the looping read of a fixed size buffer in a manner that extends a vector if a large amount of information needs to be collected and read at once (such as in the case of serialization and deserialization). For no-alloc this also allows a fixed size buffer to be used to read some arbitrary storage. I think that for embedded work this is far more typical interface and if the
usize
isn't needed by some implementations it can be dropped whereas without this implementation some storage implementations on some hardware peripherals wont work.So I think:
should be changed to:
which returns how many bytes were read, or an error
The text was updated successfully, but these errors were encountered: