From dc98c99f423835d776a23c9eb5ce93edbc3cf952 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Wed, 7 Mar 2018 19:35:57 +0100 Subject: [PATCH] `use Result` instead of an absolute path to it --- src/io/read.rs | 8 +++++--- src/io/read_exact.rs | 3 ++- src/io/write.rs | 14 ++++++++------ src/io/write_all.rs | 3 ++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/io/read.rs b/src/io/read.rs index cfb7514..1cb275e 100644 --- a/src/io/read.rs +++ b/src/io/read.rs @@ -1,5 +1,7 @@ use core::cmp; +use Result; + /// Non-blocking reader trait pub trait Read { /// An enumeration of possible errors @@ -17,13 +19,13 @@ pub trait Read { /// buf.len()`. The `n` value indicates that the buffer `buf` has been filled in with `n` bytes /// of data from this source. If `n == 0 && buf.len() > 0` then it can be assumed that this /// reader has run out of data and will not be able service any future read calls. - fn read(&mut self, buf: &mut [u8]) -> ::Result; + fn read(&mut self, buf: &mut [u8]) -> Result; } impl<'a, R: ?Sized + Read> Read for &'a mut R { type Error = R::Error; - fn read(&mut self, buf: &mut [u8]) -> ::Result { + fn read(&mut self, buf: &mut [u8]) -> Result { (**self).read(buf) } } @@ -31,7 +33,7 @@ impl<'a, R: ?Sized + Read> Read for &'a mut R { impl<'a> Read for &'a [u8] { type Error = !; - fn read(&mut self, buf: &mut [u8]) -> ::Result { + fn read(&mut self, buf: &mut [u8]) -> Result { let len = cmp::min(self.len(), buf.len()); let (head, tail) = self.split_at(len); buf[..len].copy_from_slice(head); diff --git a/src/io/read_exact.rs b/src/io/read_exact.rs index a7ccecb..69e9498 100644 --- a/src/io/read_exact.rs +++ b/src/io/read_exact.rs @@ -1,6 +1,7 @@ use core::mem; use io::Read; +use Result; /// Creates a helper that will read from a provided reader until the provided buffer is filled. /// @@ -60,7 +61,7 @@ impl> ReadExact { /// error. /// /// Otherwise will return `nb::Error::WouldBlock`. - pub fn poll(&mut self) -> ::Result<(R, B), Error> { + pub fn poll(&mut self) -> Result<(R, B), Error> { if let State::Reading { ref mut reader, ref mut buffer, ref mut position } = self.state { let buffer = buffer.as_mut(); while *position < buffer.len() { diff --git a/src/io/write.rs b/src/io/write.rs index 0e68967..6c26299 100644 --- a/src/io/write.rs +++ b/src/io/write.rs @@ -1,5 +1,7 @@ use core::{cmp, mem}; +use Result; + /// Non-blocking writer trait pub trait Write { /// An enumeration of possible errors @@ -17,24 +19,24 @@ pub trait Write { /// buf.len()`. The `n` value indicates that `n` bytes from the buffer `buf` have been written /// to this source. If `n == 0 && buf.len() > 0` then it can be assumed that this writer has /// run out of space and will not be able to service future writes. - fn write(&mut self, buf: &[u8]) -> ::Result; + fn write(&mut self, buf: &[u8]) -> Result; /// Attempt to flush the object, ensuring that any buffered data reach their destination. /// /// On success, returns `Ok(())`. /// /// If flushing cannot immediately complete, this method returns `Err(nb::Error::WouldBlock)`. - fn flush(&mut self) -> ::Result<(), Self::Error>; + fn flush(&mut self) -> Result<(), Self::Error>; } impl<'a, W: ?Sized + Write> Write for &'a mut W { type Error = W::Error; - fn write(&mut self, buf: &[u8]) -> ::Result { + fn write(&mut self, buf: &[u8]) -> Result { (**self).write(buf) } - fn flush(&mut self) -> ::Result<(), Self::Error> { + fn flush(&mut self) -> Result<(), Self::Error> { (**self).flush() } } @@ -42,7 +44,7 @@ impl<'a, W: ?Sized + Write> Write for &'a mut W { impl<'a> Write for &'a mut [u8] { type Error = !; - fn write(&mut self, buf: &[u8]) -> ::Result { + fn write(&mut self, buf: &[u8]) -> Result { let len = cmp::min(self.len(), buf.len()); let (head, tail) = mem::replace(self, &mut []).split_at_mut(len); head.copy_from_slice(&buf[..len]); @@ -50,7 +52,7 @@ impl<'a> Write for &'a mut [u8] { Ok(len) } - fn flush(&mut self) -> ::Result<(), Self::Error> { + fn flush(&mut self) -> Result<(), Self::Error> { Ok(()) } } diff --git a/src/io/write_all.rs b/src/io/write_all.rs index cbb2d22..d7bf516 100644 --- a/src/io/write_all.rs +++ b/src/io/write_all.rs @@ -1,6 +1,7 @@ use core::mem; use io::Write; +use Result; /// Creates a helper that will write all data from the provided buffer into the provided writer. /// @@ -62,7 +63,7 @@ impl> WriteAll { /// error. /// /// Otherwise will return `nb::Error::WouldBlock`. - pub fn poll(&mut self) -> ::Result<(W, B), Error> { + pub fn poll(&mut self) -> Result<(W, B), Error> { if let State::Writing { ref mut writer, ref mut buffer, ref mut position } = self.state { let buffer = buffer.as_ref(); while *position < buffer.len() {