You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xplr/src/pipe_reader.rs

27 lines
605 B
Rust

use crate::app::ExternalMsg;
use anyhow::Result;
use std::fs;
use std::io::prelude::*;
pub fn read_all(pipe: &str) -> Result<Vec<ExternalMsg>> {
let mut file = fs::OpenOptions::new()
.read(true)
.write(true)
.create(false)
.open(&pipe)?;
let mut in_str = String::new();
file.read_to_string(&mut in_str)?;
file.set_len(0)?;
if !in_str.is_empty() {
let mut msgs = vec![];
for msg in in_str.lines().map(|s| serde_yaml::from_str(s.trim())) {
msgs.push(msg?);
}
Ok(msgs)
} else {
Ok(vec![])
}
}