Skip to content

Commit

Permalink
Fix clippy warnings for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sorairolake committed Jan 5, 2024
1 parent 88df569 commit 56ce786
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ All notable changes to this project will be documented in this file.
The format is based on https://keepachangelog.com/[Keep a Changelog], and this
project adheres to https://semver.org/[Semantic Versioning].

== {compare-url}/v0.7.7\...HEAD[Unreleased]

=== Fixed

* Fix clippy warnings for examples ({pull-request-url}/70[#70])

== {compare-url}/v0.7.6\...v0.7.7[0.7.7] - 2023-12-07

=== Changed
Expand Down
12 changes: 6 additions & 6 deletions examples/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
// Lint levels of Clippy.
#![warn(clippy::cargo, clippy::nursery, clippy::pedantic)]

#[cfg(feature = "std")]
use std::io::Read;

#[cfg(feature = "std")]
fn main() -> std::process::ExitCode {
use std::{env, fs, io, process::ExitCode};
use std::{
env, fs,
io::{self, Read},
process::ExitCode,
};

let args: Vec<_> = env::args_os().skip(1).collect();

Expand All @@ -34,8 +35,7 @@ fn main() -> std::process::ExitCode {
Ok(strings) => strings,
Err(err) => {
eprintln!("Error: {err}");
return sysexits::ExitCode::try_from(err.kind())
.map_or(ExitCode::FAILURE, ExitCode::from);
return sysexits::ExitCode::from(err).into();
}
};

Expand Down
10 changes: 3 additions & 7 deletions examples/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
// Lint levels of Clippy.
#![warn(clippy::cargo, clippy::nursery, clippy::pedantic)]

#[cfg(feature = "std")]
use std::process::Termination;

#[cfg(feature = "std")]
enum ExitCode {
Same,
Expand All @@ -30,7 +27,7 @@ impl From<sysexits::ExitCode> for ExitCode {
}

#[cfg(feature = "std")]
impl Termination for ExitCode {
impl std::process::Termination for ExitCode {
fn report(self) -> std::process::ExitCode {
use std::process::ExitCode;

Expand All @@ -49,7 +46,7 @@ fn main() -> ExitCode {

let args: Vec<_> = env::args_os().skip(1).take(2).collect();

let files = if let (Some(from), Some(to)) = (args.get(0), args.get(1)) {
let files = if let (Some(from), Some(to)) = (args.first(), args.get(1)) {
(PathBuf::from(from), PathBuf::from(to))
} else {
eprintln!("Error: files are missing");
Expand All @@ -60,8 +57,7 @@ fn main() -> ExitCode {
Ok(bytes) => bytes,
Err(err) => {
eprintln!("Error: {err}");
return sysexits::ExitCode::try_from(err.kind())
.map_or(ExitCode::Trouble, ExitCode::from);
return sysexits::ExitCode::from(err).into();
}
};

Expand Down
9 changes: 5 additions & 4 deletions examples/isutf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
// Lint levels of Clippy.
#![warn(clippy::cargo, clippy::nursery, clippy::pedantic)]

#[cfg(feature = "std")]
use std::io::Read;

#[cfg(feature = "std")]
fn main() -> sysexits::ExitCode {
use std::{env, fs, io, str};
use std::{
env, fs,
io::{self, Read},
str,
};

use sysexits::ExitCode;

Expand Down

0 comments on commit 56ce786

Please sign in to comment.