Skip to content

Commit 4ee0320

Browse files
committed
Use simple io::Error for &[u8] Read and Write impl
1 parent 81734e0 commit 4ee0320

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/libstd/io/error.rs

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ impl ErrorKind {
208208
/// the heap (for normal construction via Error::new) is too costly.
209209
#[stable(feature = "io_error_from_errorkind", since = "1.14.0")]
210210
impl From<ErrorKind> for Error {
211+
#[inline]
211212
fn from(kind: ErrorKind) -> Error {
212213
Error {
213214
repr: Repr::Simple(kind)

src/libstd/io/impls.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use cmp;
12-
use io::{self, SeekFrom, Read, Write, Seek, BufRead, Error, ErrorKind};
12+
use io::{self, SeekFrom, Read, Write, Seek, BufRead, ErrorKind};
1313
use fmt;
1414
use mem;
1515

@@ -174,8 +174,7 @@ impl<'a> Read for &'a [u8] {
174174
#[inline]
175175
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
176176
if buf.len() > self.len() {
177-
return Err(Error::new(ErrorKind::UnexpectedEof,
178-
"failed to fill whole buffer"));
177+
return Err(ErrorKind::UnexpectedEof.into());
179178
}
180179
let (a, b) = self.split_at(buf.len());
181180

@@ -223,7 +222,7 @@ impl<'a> Write for &'a mut [u8] {
223222
if self.write(data)? == data.len() {
224223
Ok(())
225224
} else {
226-
Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer"))
225+
Err(ErrorKind::WriteZero.into())
227226
}
228227
}
229228

0 commit comments

Comments
 (0)