Remove unnecessary RefCell, backport to Rust 1.36

This commit is contained in:
sharkdp authored and David Peter committed 2020-05-13 18:55:24 +02:00
1 parent 244f71691d
commit 133fdd9156
4 files changed
+7 -9

No files matched your search

+1 -1
View File
@@ -18,7 +18,7 @@ matrix:
# Minimum Rust supported channel. # Minimum Rust supported channel.
- os: linux - os: linux
rust: 1.31.0 rust: 1.36.0
env: TARGET=x86_64-unknown-linux-gnu env: TARGET=x86_64-unknown-linux-gnu
+1 -1
View File
@@ -82,7 +82,7 @@ or Windows Terminal since Windows 10 1903).
### Via cargo ### Via cargo
If you have Rust 1.31 or higher, you can install `hexyl` from source via `cargo`: If you have Rust 1.36 or higher, you can install `hexyl` from source via `cargo`:
``` ```
cargo install hexyl cargo install hexyl
``` ```
+1 -2
View File
@@ -3,7 +3,6 @@ extern crate clap;
use atty; use atty;
use std::cell::RefCell;
use std::fs::File; use std::fs::File;
use std::io::{self, prelude::*, SeekFrom}; use std::io::{self, prelude::*, SeekFrom};
@@ -91,7 +90,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
let mut reader: Input = match matches.value_of("file") { let mut reader: Input = match matches.value_of("file") {
Some(filename) => Input::File(File::open(filename)?), Some(filename) => Input::File(File::open(filename)?),
None => Input::Stdin(RefCell::new(stdin.lock())), None => Input::Stdin(stdin.lock()),
}; };
let skip_arg = matches.value_of("skip"); let skip_arg = matches.value_of("skip");
+4 -5
View File
@@ -1,17 +1,16 @@
use std::cell::RefCell;
use std::fs; use std::fs;
use std::io::{self, Read, Seek, SeekFrom}; use std::io::{self, Read, Seek, SeekFrom};
pub enum Input<'a> { pub enum Input<'a> {
File(fs::File), File(fs::File),
Stdin(RefCell<io::StdinLock<'a>>), Stdin(io::StdinLock<'a>),
} }
impl<'a> Read for Input<'a> { impl<'a> Read for Input<'a> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
match *self { match *self {
Input::File(ref mut file) => file.read(buf), Input::File(ref mut file) => file.read(buf),
Input::Stdin(ref mut stdin) => stdin.borrow_mut().read(buf), Input::Stdin(ref mut stdin) => stdin.read(buf),
} }
} }
} }
@@ -31,8 +30,8 @@ impl<'a> Seek for Input<'a> {
impl<'a> Input<'a> { impl<'a> Input<'a> {
pub fn into_inner(self) -> Box<dyn Read + 'a> { pub fn into_inner(self) -> Box<dyn Read + 'a> {
match self { match self {
Self::File(file) => Box::new(file), Input::File(file) => Box::new(file),
Self::Stdin(stdin) => Box::new(stdin.into_inner()), Input::Stdin(stdin) => Box::new(stdin),
} }
} }
} }