diff --git a/Cargo.toml b/Cargo.toml index dc353f2..0c034a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ferris-says" -version = "0.2.1" +version = "0.3.1" authors = ["Michael Gattozzi "] description = "A Rust flavored replacement for the classic cowsay" documentation = "https://docs.rs/ferris-says" diff --git a/fsays/Cargo.toml b/fsays/Cargo.toml index bbe17a0..8b29d66 100644 --- a/fsays/Cargo.toml +++ b/fsays/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "fsays" -version = "0.1.0" +version = "0.3.0" authors = ["Michael Gattozzi "] -edition = "2018" +edition = "2021" description = "A Rust flavored replacement for the classic cowsay" documentation = "https://docs.rs/ferris-says" homepage = "https://github.com/mgattozzi/ferris-says" @@ -20,6 +20,5 @@ license = "MIT/Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ferris-says = "0.2" +ferris-says = { version = "0.3", path = ".." } clap = "2.25" -error-chain = "0.10" diff --git a/fsays/src/main.rs b/fsays/src/main.rs index 0b52197..3c3a19c 100644 --- a/fsays/src/main.rs +++ b/fsays/src/main.rs @@ -1,17 +1,12 @@ #![recursion_limit = "1024"] -extern crate clap; -extern crate ferris_says; -#[macro_use] -extern crate error_chain; - use clap::{App, Arg}; use ferris_says::*; +use std::error::Error; use std::fs::File; use std::io::{stderr, stdin, stdout, BufReader, BufWriter, Read, Write}; use std::process::exit; - -error_chain! {} +use std::str; // Constants used for err messages const ARGS: &str = "Invalid argument passed to fsays caused an error"; @@ -25,19 +20,11 @@ fn main() { writeln!(stderr, "error: {}", e).expect(STDERR); - for e in e.iter().skip(1) { - writeln!(stderr, "caused by: {}", e).expect(STDERR); - } - - if let Some(backtrace) = e.backtrace() { - writeln!(stderr, "backtrace: {:?}", backtrace).expect(STDERR); - } - exit(1); } } -fn run() -> Result<()> { +fn run() -> Result<(), Box> { let args = App::new("Ferris Says") .version("0.1") .author("Michael Gattozzi ") @@ -68,7 +55,7 @@ fn run() -> Result<()> { ) .get_matches(); - let width = args.value_of("WIDTH").unwrap().parse().chain_err(|| ARGS)?; + let width = args.value_of("WIDTH").unwrap().parse().map_err(|_| ARGS)?; let stdin = stdin(); let stdout = stdout(); @@ -79,42 +66,43 @@ fn run() -> Result<()> { // Read in files and say them with Ferris let reader = files .map(|i| { - let reader = BufReader::new(File::open(i).chain_err(|| INPUT)?); - Ok(reader - .bytes() - .fold(Ok(Vec::new()), |a: Result>, b| { + let reader = BufReader::new(File::open(i).map_err(|_| INPUT)?); + Ok(reader.bytes().fold( + Ok(Vec::new()), + |a: Result, Box>, b| { if let Ok(mut a) = a { - a.push(b.chain_err(|| INPUT)?); + a.push(b.map_err(|_| INPUT)?); Ok(a) } else { a } - })?) + }, + )?) }) - .collect::>>>(); + .collect::, Box>>>(); for i in reader { - say(&i?, width, &mut writer).chain_err(|| STDOUT)?; + say(str::from_utf8(&i?)?, width, &mut writer).map_err(|_| STDOUT)?; } Ok(()) } else if let Some(other_args) = args.values_of("TEXT") { let s = other_args.collect::>().join(" "); - say(s.as_bytes(), width, &mut writer).chain_err(|| STDOUT)?; + say(&s, width, &mut writer).map_err(|_| STDOUT)?; Ok(()) } else { let reader = BufReader::new(stdin.lock()).bytes().fold( Ok(Vec::new()), - |a: Result>, b| { + |a: Result, Box>, b| { if let Ok(mut a) = a { - a.push(b.chain_err(|| INPUT)?); + a.push(b.map_err(|_| INPUT)?); Ok(a) } else { a } }, )?; - say(&reader, width, &mut writer).chain_err(|| STDOUT)?; + say(str::from_utf8(&reader)?, width, &mut writer).map_err(|_| STDOUT)?; Ok(()) }