Refactor {send,read}_message() #11

Merged
eNV25 merged 2 commits from main into main 2024-02-16 09:53:21 +01:00
eNV25 commented 2024-02-15 15:07:24 +01:00 (Migrated from github.com)
No description provided.
ryze312 commented 2024-02-16 09:45:40 +01:00 (Migrated from github.com)

Thanks for another PR! Looking at the changes, we now lock the streams for buffered I/O (which I should have done before) and use a more elegant length buffer using to_ne_bytes(). Sounds good!

Thanks for another PR! Looking at the changes, we now lock the streams for buffered I/O (*which I should have done before*) and use a more elegant length buffer using `to_ne_bytes()`. Sounds good!
ryze312 (Migrated from github.com) requested changes 2024-02-16 09:52:45 +01:00
ryze312 (Migrated from github.com) commented 2024-02-16 09:52:24 +01:00

I think it would be more readable to do a binding for Take here

    let mut reader = stdin.take(len as u64);
    let mut msg = String::with_capacity(len as usize);
    reader.read_to_string(&mut msg)?;
I think it would be more readable to do a binding for `Take` here ```suggestion let mut reader = stdin.take(len as u64); let mut msg = String::with_capacity(len as usize); reader.read_to_string(&mut msg)?; ```
eNV25 commented 2024-02-16 15:15:23 +01:00 (Migrated from github.com)

Thanks for another PR! Looking at the changes, we now lock the streams for buffered I/O (which I should have done before) and use a more elegant length buffer using to_ne_bytes(). Sounds good!

The reason I removed the BufReader is that the docs said it doesn't make much difference if only used once.

Sorry for not adding some context.

> Thanks for another PR! Looking at the changes, we now lock the streams for buffered I/O (_which I should have done before_) and use a more elegant length buffer using `to_ne_bytes()`. Sounds good! The reason I removed the `BufReader` is that the docs said it doesn't make much difference if only used once. Sorry for not adding some context.
ryze312 commented 2024-02-16 16:40:04 +01:00 (Migrated from github.com)

No worries! I looked it up myself, StdinLock and StdoutLock both implement BufRead :3

No worries! I looked it up myself, [`StdinLock`](https://doc.rust-lang.org/std/io/struct.StdinLock.html) and [`StdoutLock`](https://doc.rust-lang.org/std/io/struct.StdinLock.html) both implement [`BufRead`](https://doc.rust-lang.org/std/io/trait.BufRead.html) :3
Sign in to join this conversation.
No description provided.