Skip to content

Commit

Permalink
simplify read_to_vec
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed May 6, 2024
1 parent 179f33a commit 2d6268b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/status_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl StatusCmd {
}

pub fn receive_blocks(&mut self) -> Result<Option<Vec<Block>>> {
match read_to_vec(&mut self.output, &mut self.buf) {
match read_to_vec(&self.output, &mut self.buf) {
Ok(0) => bail!("status command exited"),
Ok(_n) => (),
Err(e) if e.kind() == ErrorKind::WouldBlock => return Ok(None),
Expand Down
7 changes: 2 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ use serde_json::{Deserializer, Error as JsonError};
/// Read from a raw file descriptor to the vector.
///
/// Appends data at the end of the buffer. Resizes vector as needed.
#[allow(clippy::needless_pass_by_ref_mut)]
pub fn read_to_vec(fd: &mut impl AsFd, buf: &mut Vec<u8>) -> io::Result<usize> {
if buf.capacity() - buf.len() < 1024 {
buf.reserve(buf.capacity().max(1024));
}
pub fn read_to_vec(fd: impl AsFd, buf: &mut Vec<u8>) -> io::Result<usize> {
buf.reserve(1024);

let res = unsafe {
libc::read(
Expand Down
2 changes: 1 addition & 1 deletion src/wm_info_provider/hyprland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Ipc {
self.sock2_buf.drain(..=i);
return Ok(event);
}
if read_to_vec(&mut self.sock2, &mut self.sock2_buf)? == 0 {
if read_to_vec(&self.sock2, &mut self.sock2_buf)? == 0 {
return Err(io::Error::new(
io::ErrorKind::BrokenPipe,
"hyprland socked disconnected",
Expand Down

0 comments on commit 2d6268b

Please sign in to comment.