From 5bf1212b2ab1bf6cc68a3b1f563738db8048df82 Mon Sep 17 00:00:00 2001 From: mars Date: Wed, 12 Apr 2023 17:16:07 -0400 Subject: [PATCH] Import Path in main.rs --- src/main.rs | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4dec4f2..a9d82c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,15 +20,10 @@ use std::{ env::args, ffi::OsString, - fs::{ File, OpenOptions }, - io::{ - Read, - stdout, - Stdout, - Write, - }, + fs::{File, OpenOptions}, + io::{stdout, Read, Stdout, Write}, os::fd::FromRawFd, - path::PathBuf, + path::{Path, PathBuf}, sync::Arc, }; @@ -358,22 +353,17 @@ impl State { handle = match command_parts.get(1) { Some(part) => OsString::from(part), None => { - return Err( - format!("{}: No file name.", command) - ); - }, + return Err(format!("{}: No file name.", command)); + } }; } - self.write_buffer(handle).map_err(|err| { - format!("{}", err) - })?; - }, + self.write_buffer(handle) + .map_err(|err| format!("{}", err))?; + } command => { - return Err( - format!("{}: Unrecognized command.", command) - ); - }, + return Err(format!("{}: Unrecognized command.", command)); + } } } Ok(()) @@ -420,13 +410,13 @@ fn main() -> Result<()> { let stdin = 0; // get stdin as a file descriptor if unsafe { libc::isatty(stdin) } == 0 { unsafe { File::from_raw_fd(stdin) } - } else { File::open("/dev/null").unwrap() } - }, + } else { + File::open("/dev/null").unwrap() + } + } Some(path) => { let input_file = Path::new(path); - file_name = Some(OsString::from( - input_file.clone().display().to_string() - )); + file_name = Some(OsString::from(input_file.clone().display().to_string())); File::open(input_file).unwrap_or_else(|_| { let mut err = String::new(); @@ -438,8 +428,10 @@ fn main() -> Result<()> { eprintln!("{}: {}: {}", argv[0], path, err); exit(EX_UNAVAILABLE); }) - }, - }.read_to_end(&mut buf).unwrap(); + } + } + .read_to_end(&mut buf) + .unwrap(); let text = String::from_utf8(buf).unwrap_or_else(|_| { eprintln!(