Closed dobromyslov closed 2 years ago
See https://github.com/technocreatives/core2/blob/7bf2611bd9a52b438300c640e142ad5c1298b05b/src/io/impls.rs#L130
There is no check if the buffer is less than the data to be written.
Maybe it should check this case and return ErrorKind::WriteZero?https://github.com/technocreatives/core2/blob/7bf2611bd9a52b438300c640e142ad5c1298b05b/src/io/error.rs#L181
ErrorKind::WriteZero
As a workaround I have to do cursor.write() and then compare the result with the data length like this:
let data = &[1_u8; 2]; match cursor.write(data) { Err(_) => Err(MqttFixedHeaderError::WriteError), Ok(size) => if size < data.len() { Err(MqttFixedHeaderError::WriteError) } else { Ok(size) } }
Or should I use write_all() instead?
write_all()
Definitely. That's my fault. I've read official docs https://doc.rust-lang.org/std/io/trait.Write.html#tymethod.write and understood that I need write_all().
See https://github.com/technocreatives/core2/blob/7bf2611bd9a52b438300c640e142ad5c1298b05b/src/io/impls.rs#L130
There is no check if the buffer is less than the data to be written.
Maybe it should check this case and return
ErrorKind::WriteZero
?https://github.com/technocreatives/core2/blob/7bf2611bd9a52b438300c640e142ad5c1298b05b/src/io/error.rs#L181As a workaround I have to do cursor.write() and then compare the result with the data length like this: