From 9d634cb2a7cc045d3e3b8da0ad1e40ffc3cb525a Mon Sep 17 00:00:00 2001 From: yjhmelody <465402634@qq.com> Date: Wed, 13 Nov 2019 12:42:59 +0800 Subject: [PATCH] refactor io dir to be same with std --- src/io/buf_reader.rs | 6 ++---- src/io/buf_writer.rs | 6 ++---- src/io/mod.rs | 2 ++ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/io/buf_reader.rs b/src/io/buf_reader.rs index 1d00b526..e6d8e669 100644 --- a/src/io/buf_reader.rs +++ b/src/io/buf_reader.rs @@ -4,11 +4,9 @@ use std::{cmp, fmt}; use pin_project_lite::pin_project; -use crate::io::{self, BufRead, Read, Seek, SeekFrom}; +use crate::io::{self, BufRead, Read, Seek, SeekFrom, DEFAULT_BUF_SIZE}; use crate::task::{Context, Poll}; -const DEFAULT_CAPACITY: usize = 8 * 1024; - pin_project! { /// Adds buffering to any reader. /// @@ -72,7 +70,7 @@ impl BufReader { /// # Ok(()) }) } /// ``` pub fn new(inner: R) -> BufReader { - BufReader::with_capacity(DEFAULT_CAPACITY, inner) + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) } /// Creates a new buffered reader with the specified capacity. diff --git a/src/io/buf_writer.rs b/src/io/buf_writer.rs index 8fa9eba4..35b511f8 100644 --- a/src/io/buf_writer.rs +++ b/src/io/buf_writer.rs @@ -4,11 +4,9 @@ use std::pin::Pin; use pin_project_lite::pin_project; use crate::io::write::WriteExt; -use crate::io::{self, Seek, SeekFrom, Write}; +use crate::io::{self, Seek, SeekFrom, Write, DEFAULT_BUF_SIZE}; use crate::task::{Context, Poll, ready}; -const DEFAULT_CAPACITY: usize = 8 * 1024; - pin_project! { /// Wraps a writer and buffers its output. /// @@ -107,7 +105,7 @@ impl BufWriter { /// # Ok(()) }) } /// ``` pub fn new(inner: W) -> BufWriter { - BufWriter::with_capacity(DEFAULT_CAPACITY, inner) + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) } /// Creates a new `BufWriter` with the specified buffer capacity. diff --git a/src/io/mod.rs b/src/io/mod.rs index 4e832305..065aaab5 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -269,6 +269,8 @@ //! [`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html //! [`.unwrap()`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap +const DEFAULT_BUF_SIZE: usize = 8 * 1024; + cfg_std! { #[doc(inline)] pub use std::io::{Error, ErrorKind, IoSlice, IoSliceMut, Result, SeekFrom};