From 0448d438d13d1486fdbc678e54685e5c9b5a12b8 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sat, 26 Dec 2020 00:41:25 -0800 Subject: fix indentation to 2 spaces --- src/error.rs | 68 +++++++++++++++++++++++------------------------ src/main.rs | 87 ++++++++++++++++++++++++++++++------------------------------ 2 files changed, 77 insertions(+), 78 deletions(-) (limited to 'src') diff --git a/src/error.rs b/src/error.rs index adb19bc..8e51880 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,54 +2,54 @@ use crate::path::GenericPath; type ParseError<'a> = - lalrpop_util::ParseError, &'a str>; + lalrpop_util::ParseError, &'a str>; #[derive(Debug)] pub enum Error { - IO(std::io::Error), - Parse(String), - PathListHasEmptyComponents(String), - PathIsAFile(GenericPath), - PathIsRelative(GenericPath), - PathInvalid(GenericPath), + IO(std::io::Error), + Parse(String), + PathListHasEmptyComponents(String), + PathIsAFile(GenericPath), + PathIsRelative(GenericPath), + PathInvalid(GenericPath), } impl std::error::Error for Error { } impl std::fmt::Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Error::IO(e) => e.fmt(f), - Error::Parse(e) => e.fmt(f), - Error::PathListHasEmptyComponents(path_list) => - f.write_fmt(format_args!( - "Path list has empty components: {}", - path_list)), - Error::PathIsAFile(path) => - f.write_fmt(format_args!( - "There's a file at {}, not a directory.", - path)), - Error::PathIsRelative(path) => - f.write_fmt(format_args!( - "The path {} is relative, not absolute.", - path)), - Error::PathInvalid(path) => - f.write_fmt(format_args!( - "This isn't a valid path. {}", - path)), - } + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::IO(e) => e.fmt(f), + Error::Parse(e) => e.fmt(f), + Error::PathListHasEmptyComponents(path_list) => + f.write_fmt(format_args!( + "Path list has empty components: {}", + path_list)), + Error::PathIsAFile(path) => + f.write_fmt(format_args!( + "There's a file at {}, not a directory.", + path)), + Error::PathIsRelative(path) => + f.write_fmt(format_args!( + "The path {} is relative, not absolute.", + path)), + Error::PathInvalid(path) => + f.write_fmt(format_args!( + "This isn't a valid path. {}", + path)), } + } } impl From for Error { - fn from(e: std::io::Error) -> Error { - Error::IO(e) - } + fn from(e: std::io::Error) -> Error { + Error::IO(e) + } } impl From> for Error { - fn from(e: ParseError<'_>) -> Error { - Error::Parse(format!("{}", e)) - } + fn from(e: ParseError<'_>) -> Error { + Error::Parse(format!("{}", e)) + } } diff --git a/src/main.rs b/src/main.rs index 36fb284..60c14ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,76 +12,75 @@ pub mod result; pub enum Input { - String(String), - End, + String(String), + End, } fn main() -> Result<()> { - std::process::exit(match repl() { - Ok(()) => 0, - Err(ref e) => { - eprintln!("{}", e); - 1 - } - }) + std::process::exit(match repl() { + Ok(()) => 0, + Err(ref e) => { + eprintln!("{}", e); + 1 + } + }) } fn repl() -> Result<()> { - println!("Hello, terminal!"); + println!("Hello, terminal!"); - loop { - prompt()?; + loop { + prompt()?; - let input = read()?; - match input { - Input::String(string) => execute(&string)?, - Input::End => break, - } + let input = read()?; + match input { + Input::String(string) => execute(&string)?, + Input::End => break, } + } - Ok(()) + Ok(()) } fn prompt() -> Result<()> { - print!("$ "); - io::stdout().flush()?; + print!("$ "); + io::stdout().flush()?; - Ok(()) + Ok(()) } fn read() -> Result { - let mut input = String::new(); - let n_bytes = io::stdin().read_line(&mut input)?; - - if n_bytes == 0 { - Ok(Input::End) - } else { - Ok(Input::String(input)) - } + let mut input = String::new(); + let n_bytes = io::stdin().read_line(&mut input)?; + + if n_bytes == 0 { + Ok(Input::End) + } else { + Ok(Input::String(input)) + } } fn execute(input: &str) -> Result<()> { - let invocation = commandline::InvocationParser::new().parse(input)?; - - println!("{}", input); - - match invocation.as_slice() { - ["paths", path_list, ..] => { - let paths = path::parse_path_list(path_list)?; - for path in &paths { - println!("{}", path); - } - }, - _ => { - println!("invocation '{:?}'", invocation); + let invocation = commandline::InvocationParser::new().parse(input)?; + + println!("{}", input); + + match invocation.as_slice() { + ["paths", path_list, ..] => { + let paths = path::parse_path_list(path_list)?; + for path in &paths { + println!("{}", path); } + }, + _ => { + println!("invocation '{:?}'", invocation); } + } - Ok(()) + Ok(()) } - -- cgit 1.4.1