From 03c59fabd75bf4dd7ded042f775f98187aae2982 Mon Sep 17 00:00:00 2001 From: hms5232 <43672033+hms5232@users.noreply.github.com> Date: Sat, 21 Oct 2023 20:08:58 +0800 Subject: [PATCH 01/10] docs: update outdated library part in README The latest version is 0.3.1, but the library usage is for 0.2 To avoid leaving out update version in README, I add the way of cargo command. --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 302264d..bda0fc2 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,13 @@ Put the following in your `Cargo.toml`: ```toml [dependencies] -ferris-says = "0.2" +ferris-says = "0.3.1" +``` + +or run: + +```sh +cargo add ferris-says ``` Then import the crate with: @@ -32,7 +38,7 @@ use ferris_says::say; use std::io::{ stdout, BufWriter }; fn main() { - let out = b"Hello fellow Rustaceans!"; + let out = "Hello fellow Rustaceans!"; let width = 24; let mut writer = BufWriter::new(stdout()); From fcb2ce5d3935a2e6c095af32a783a69cfc5946cb Mon Sep 17 00:00:00 2001 From: Joshua Byrd Date: Wed, 20 Dec 2023 17:18:32 +1000 Subject: [PATCH 02/10] Remove extern --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 302264d..dabbe03 100644 --- a/README.md +++ b/README.md @@ -15,19 +15,11 @@ Put the following in your `Cargo.toml`: ferris-says = "0.2" ``` -Then import the crate with: - -```rust -extern crate ferris_says; -``` - ### Example The following bit of code will write the byte string to STDOUT ```rust -extern crate ferris_says; - use ferris_says::say; use std::io::{ stdout, BufWriter }; From b578e68df0c2a40b1ef233170ec8615c614bf949 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 13 Jan 2024 17:20:47 -0800 Subject: [PATCH 03/10] Delete Travis CI and AppVeyor badges from Cargo.toml --- Cargo.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0c034a4..7deef61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,10 +17,6 @@ categories = [ ] license = "MIT/Apache-2.0" -[badges] -travis-ci = { repository = "mgattozzi/ferris-says", branch = "master" } -appveyor = { repository = "mgattozzi/ferris-says", branch = "master", service = "github" } - [lib] name = "ferris_says" From 9e34316b403d6a34fdf75f9a2372c3997389c1ee Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 13 Jan 2024 17:30:50 -0800 Subject: [PATCH 04/10] Delete redundant lib name from Cargo.toml --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0c034a4..1347780 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,9 +21,6 @@ license = "MIT/Apache-2.0" travis-ci = { repository = "mgattozzi/ferris-says", branch = "master" } appveyor = { repository = "mgattozzi/ferris-says", branch = "master", service = "github" } -[lib] -name = "ferris_says" - [features] clippy = [] From 8c723709cd9404be30034fa70144abb881afb646 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 13 Jan 2024 17:33:02 -0800 Subject: [PATCH 05/10] Update repository in crates.io metadata and delete homepage --- Cargo.toml | 3 +-- fsays/Cargo.toml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0c034a4..0ff31cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,7 @@ version = "0.3.1" authors = ["Michael Gattozzi "] description = "A Rust flavored replacement for the classic cowsay" documentation = "https://docs.rs/ferris-says" -homepage = "https://github.com/mgattozzi/ferris-says" -repository = "https://github.com/mgattozzi/ferris-says" +repository = "https://github.com/rust-lang/ferris-says" readme = "README.md" keywords = ["ferris", "cowsay", "print", "fsays", "rustacean"] categories = [ diff --git a/fsays/Cargo.toml b/fsays/Cargo.toml index 8b29d66..bbe76e2 100644 --- a/fsays/Cargo.toml +++ b/fsays/Cargo.toml @@ -5,8 +5,7 @@ authors = ["Michael Gattozzi "] edition = "2021" description = "A Rust flavored replacement for the classic cowsay" documentation = "https://docs.rs/ferris-says" -homepage = "https://github.com/mgattozzi/ferris-says" -repository = "https://github.com/mgattozzi/ferris-says" +repository = "https://github.com/rust-lang/ferris-says" keywords = ["ferris", "cowsay", "print", "fsays", "rustacean"] categories = [ "text-processing", From a30724ef1edf8894987510fcb876a68ce355b7d6 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 13 Jan 2024 17:56:28 -0800 Subject: [PATCH 06/10] Set up GitHub Actions --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ee17f5d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI + +on: + push: + pull_request: + +jobs: + test: + name: Rust ${{matrix.rust}} on ${{matrix.os}} + runs-on: ${{matrix.os}}-latest + strategy: + fail-fast: false + matrix: + include: + - {rust: stable, os: ubuntu} + - {rust: stable, os: macos} + - {rust: stable, os: windows} + - {rust: beta, os: ubuntu} + - {rust: nightly, os: ubuntu} + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{matrix.rust}} + - run: cargo check + - run: cargo check --features clippy + - run: cargo test + - run: cargo test --features clippy + - run: cargo doc From 7dee38ca4db3c61222734e61d05d7bb3d28cc36f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 13 Jan 2024 17:56:39 -0800 Subject: [PATCH 07/10] Delete AppVeyor configuration --- appveyor.yml | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 9412f84..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,28 +0,0 @@ -branches: - except: - - gh_pages -os: - - Visual Studio 2015 -environment: - matrix: - - TARGET: i686-pc-windows-msvc - BITS: 32 - - TARGET: x86_64-pc-windows-msvc - BITS: 64 -install: - # Install Rust - - curl -sSf -o rustup-init.exe https://win.rustup.rs/ - - rustup-init.exe -y --default-toolchain=stable-%TARGET% - - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin - - rustc -V - - cargo -V - -build: false - -test_script: - - cargo build - - cargo test - -cache: - - target - - C:\Users\appveyor\.cargo\registry From 36a1b0e14673e65fb02114bfb78fcb2be7fad0a0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 13 Jan 2024 17:56:45 -0800 Subject: [PATCH 08/10] Delete Travis CI configuration --- .travis.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3983519..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -sudo: false -language: rust -os: - - linux - - osx -rust: - - stable - - beta - - nightly -matrix: - allow_failures: - - rust: - - beta - - nightly -script: -- cargo build -- cargo test -- cargo build --features clippy -- cargo test --features clippy -- cargo doc From f9271a3be1d636cefe1c7dd5db423fbf15a4b75b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 13 Jan 2024 18:02:11 -0800 Subject: [PATCH 09/10] Use SPDX syntax for license expression --- Cargo.toml | 2 +- fsays/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0c034a4..cd6d16e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ categories = [ "command-line-utilities", "value-formatting" ] -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" [badges] travis-ci = { repository = "mgattozzi/ferris-says", branch = "master" } diff --git a/fsays/Cargo.toml b/fsays/Cargo.toml index 8b29d66..e39c0f0 100644 --- a/fsays/Cargo.toml +++ b/fsays/Cargo.toml @@ -15,7 +15,7 @@ categories = [ "command-line-utilities", "value-formatting" ] -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 96fc95580809ae1033da33b9ecb05b91c1356115 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 13 Jan 2024 21:13:05 -0800 Subject: [PATCH 10/10] Simplify reading of stdin and files --- fsays/src/main.rs | 49 +++++++++++------------------------------------ 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/fsays/src/main.rs b/fsays/src/main.rs index 3c3a19c..22fe6c9 100644 --- a/fsays/src/main.rs +++ b/fsays/src/main.rs @@ -3,8 +3,8 @@ 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::fs; +use std::io::{stderr, stdin, stdout, BufWriter, Read, Write}; use std::process::exit; use std::str; @@ -57,53 +57,26 @@ fn run() -> Result<(), Box> { let width = args.value_of("WIDTH").unwrap().parse().map_err(|_| ARGS)?; - let stdin = stdin(); + let mut stdin = stdin(); let stdout = stdout(); let mut writer = BufWriter::new(stdout.lock()); if let Some(files) = args.values_of("FILES") { // Read in files and say them with Ferris - let reader = files - .map(|i| { - 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.map_err(|_| INPUT)?); - Ok(a) - } else { - a - } - }, - )?) - }) - .collect::, Box>>>(); - for i in reader { - say(str::from_utf8(&i?)?, width, &mut writer).map_err(|_| STDOUT)?; + for f in files { + let content = fs::read_to_string(f).map_err(|_| INPUT)?; + say(&content, 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, width, &mut writer).map_err(|_| STDOUT)?; - + let text = other_args.collect::>().join(" "); + say(&text, width, &mut writer).map_err(|_| STDOUT)?; Ok(()) } else { - let reader = BufReader::new(stdin.lock()).bytes().fold( - Ok(Vec::new()), - |a: Result, Box>, b| { - if let Ok(mut a) = a { - a.push(b.map_err(|_| INPUT)?); - Ok(a) - } else { - a - } - }, - )?; - say(str::from_utf8(&reader)?, width, &mut writer).map_err(|_| STDOUT)?; - + let mut input = String::new(); + stdin.read_to_string(&mut input).map_err(|_| INPUT)?; + say(&input, width, &mut writer).map_err(|_| STDOUT)?; Ok(()) } }