Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5f62b271
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5f62b271
编写于
4月 25, 2017
作者:
C
Corey Farwell
提交者:
GitHub
4月 25, 2017
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #41463 - SergioBenitez:master, r=alexcrichton
Add internal accessor methods to io::{Chain, Take}. Resolves #29067.
上级
2a320c32
c168d8bb
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
151 addition
and
0 deletion
+151
-0
src/doc/unstable-book/src/SUMMARY.md
src/doc/unstable-book/src/SUMMARY.md
+1
-0
src/doc/unstable-book/src/library-features/more-io-inner-methods.md
...stable-book/src/library-features/more-io-inner-methods.md
+11
-0
src/libstd/io/mod.rs
src/libstd/io/mod.rs
+139
-0
未找到文件。
src/doc/unstable-book/src/SUMMARY.md
浏览文件 @
5f62b271
...
...
@@ -160,6 +160,7 @@
-
[
linked_list_extras
](
library-features/linked-list-extras.md
)
-
[
lookup_host
](
library-features/lookup-host.md
)
-
[
manually_drop
](
library-features/manually-drop.md
)
-
[
more_io_inner_methods
](
library-features/more-io-inner-methods.md
)
-
[
mpsc_select
](
library-features/mpsc-select.md
)
-
[
n16
](
library-features/n16.md
)
-
[
never_type_impls
](
library-features/never-type-impls.md
)
...
...
src/doc/unstable-book/src/library-features/more-io-inner-methods.md
0 → 100644
浏览文件 @
5f62b271
# `more_io_inner_methods`
The tracking issue for this feature is: [#41519]
[
#41519
]:
https://github.com/rust-lang/rust/issues/41519
------------------------
This feature enables several internal accessor methods on structures in
`std::io`
including
`Take::{get_ref, get_mut}`
and
`Chain::{into_inner, get_ref,
get_mut}`
.
src/libstd/io/mod.rs
浏览文件 @
5f62b271
...
...
@@ -1504,6 +1504,87 @@ pub struct Chain<T, U> {
done_first
:
bool
,
}
impl
<
T
,
U
>
Chain
<
T
,
U
>
{
/// Consumes the `Chain`, returning the wrapped readers.
///
/// # Examples
///
/// ```
/// #![feature(more_io_inner_methods)]
///
/// # use std::io;
/// use std::io::prelude::*;
/// use std::fs::File;
///
/// # fn foo() -> io::Result<()> {
/// let mut foo_file = File::open("foo.txt")?;
/// let mut bar_file = File::open("bar.txt")?;
///
/// let chain = foo_file.chain(bar_file);
/// let (foo_file, bar_file) = chain.into_inner();
/// # Ok(())
/// # }
/// ```
#[unstable(feature
=
"more_io_inner_methods"
,
issue=
"41519"
)]
pub
fn
into_inner
(
self
)
->
(
T
,
U
)
{
(
self
.first
,
self
.second
)
}
/// Gets references to the underlying readers in this `Chain`.
///
/// # Examples
///
/// ```
/// #![feature(more_io_inner_methods)]
///
/// # use std::io;
/// use std::io::prelude::*;
/// use std::fs::File;
///
/// # fn foo() -> io::Result<()> {
/// let mut foo_file = File::open("foo.txt")?;
/// let mut bar_file = File::open("bar.txt")?;
///
/// let chain = foo_file.chain(bar_file);
/// let (foo_file, bar_file) = chain.get_ref();
/// # Ok(())
/// # }
/// ```
#[unstable(feature
=
"more_io_inner_methods"
,
issue=
"41519"
)]
pub
fn
get_ref
(
&
self
)
->
(
&
T
,
&
U
)
{
(
&
self
.first
,
&
self
.second
)
}
/// Gets mutable references to the underlying readers in this `Chain`.
///
/// Care should be taken to avoid modifying the internal I/O state of the
/// underlying readers as doing so may corrupt the internal state of this
/// `Chain`.
///
/// # Examples
///
/// ```
/// #![feature(more_io_inner_methods)]
///
/// # use std::io;
/// use std::io::prelude::*;
/// use std::fs::File;
///
/// # fn foo() -> io::Result<()> {
/// let mut foo_file = File::open("foo.txt")?;
/// let mut bar_file = File::open("bar.txt")?;
///
/// let mut chain = foo_file.chain(bar_file);
/// let (foo_file, bar_file) = chain.get_mut();
/// # Ok(())
/// # }
/// ```
#[unstable(feature
=
"more_io_inner_methods"
,
issue=
"41519"
)]
pub
fn
get_mut
(
&
mut
self
)
->
(
&
mut
T
,
&
mut
U
)
{
(
&
mut
self
.first
,
&
mut
self
.second
)
}
}
#[stable(feature
=
"std_debug"
,
since
=
"1.16.0"
)]
impl
<
T
:
fmt
::
Debug
,
U
:
fmt
::
Debug
>
fmt
::
Debug
for
Chain
<
T
,
U
>
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
...
...
@@ -1616,6 +1697,64 @@ pub fn limit(&self) -> u64 { self.limit }
pub
fn
into_inner
(
self
)
->
T
{
self
.inner
}
/// Gets a reference to the underlying reader.
///
/// # Examples
///
/// ```
/// #![feature(more_io_inner_methods)]
///
/// use std::io;
/// use std::io::prelude::*;
/// use std::fs::File;
///
/// # fn foo() -> io::Result<()> {
/// let mut file = File::open("foo.txt")?;
///
/// let mut buffer = [0; 5];
/// let mut handle = file.take(5);
/// handle.read(&mut buffer)?;
///
/// let file = handle.get_ref();
/// # Ok(())
/// # }
/// ```
#[unstable(feature
=
"more_io_inner_methods"
,
issue=
"41519"
)]
pub
fn
get_ref
(
&
self
)
->
&
T
{
&
self
.inner
}
/// Gets a mutable reference to the underlying reader.
///
/// Care should be taken to avoid modifying the internal I/O state of the
/// underlying reader as doing so may corrupt the internal limit of this
/// `Take`.
///
/// # Examples
///
/// ```
/// #![feature(more_io_inner_methods)]
///
/// use std::io;
/// use std::io::prelude::*;
/// use std::fs::File;
///
/// # fn foo() -> io::Result<()> {
/// let mut file = File::open("foo.txt")?;
///
/// let mut buffer = [0; 5];
/// let mut handle = file.take(5);
/// handle.read(&mut buffer)?;
///
/// let file = handle.get_mut();
/// # Ok(())
/// # }
/// ```
#[unstable(feature
=
"more_io_inner_methods"
,
issue=
"41519"
)]
pub
fn
get_mut
(
&
mut
self
)
->
&
mut
T
{
&
mut
self
.inner
}
}
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录