Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
16699635
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,发现更多精彩内容 >>
提交
16699635
编写于
7月 24, 2016
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add DirEntry doc examples
上级
dad29a6d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
0 deletion
+71
-0
src/libstd/fs.rs
src/libstd/fs.rs
+55
-0
src/libstd/sys/unix/ext/fs.rs
src/libstd/sys/unix/ext/fs.rs
+16
-0
未找到文件。
src/libstd/fs.rs
浏览文件 @
16699635
...
...
@@ -846,6 +846,26 @@ pub fn path(&self) -> PathBuf { self.0.path() }
/// On Windows this function is cheap to call (no extra system calls
/// needed), but on Unix platforms this function is the equivalent of
/// calling `symlink_metadata` on the path.
///
/// # Examples
///
/// ```
/// use std::fs;
///
/// if let Ok(entries) = fs::read_dir(".") {
/// for entry in entries {
/// if let Ok(entry) = entry {
/// // Here, `entry` is a `DirEntry`.
/// if let Ok(metadata) = entry.metadata() {
/// // Now let's show our entry's permissions!
/// println!("{:?}: {:?}", entry.path(), metadata.permissions());
/// } else {
/// println!("Couldn't get metadata for {:?}", entry.path());
/// }
/// }
/// }
/// }
/// ```
#[stable(feature
=
"dir_entry_ext"
,
since
=
"1.1.0"
)]
pub
fn
metadata
(
&
self
)
->
io
::
Result
<
Metadata
>
{
self
.0
.metadata
()
.map
(
Metadata
)
...
...
@@ -861,6 +881,26 @@ pub fn metadata(&self) -> io::Result<Metadata> {
/// On Windows and most Unix platforms this function is free (no extra
/// system calls needed), but some Unix platforms may require the equivalent
/// call to `symlink_metadata` to learn about the target file type.
///
/// # Examples
///
/// ```
/// use std::fs;
///
/// if let Ok(entries) = fs::read_dir(".") {
/// for entry in entries {
/// if let Ok(entry) = entry {
/// // Here, `entry` is a `DirEntry`.
/// if let Ok(file_type) = entry.file_type() {
/// // Now let's show our entry's file type!
/// println!("{:?}: {:?}", entry.path(), file_type);
/// } else {
/// println!("Couldn't get file type for {:?}", entry.path());
/// }
/// }
/// }
/// }
/// ```
#[stable(feature
=
"dir_entry_ext"
,
since
=
"1.1.0"
)]
pub
fn
file_type
(
&
self
)
->
io
::
Result
<
FileType
>
{
self
.0
.file_type
()
.map
(
FileType
)
...
...
@@ -868,6 +908,21 @@ pub fn file_type(&self) -> io::Result<FileType> {
/// Returns the bare file name of this directory entry without any other
/// leading path component.
///
/// # Examples
///
/// ```
/// use std::fs;
///
/// if let Ok(entries) = fs::read_dir(".") {
/// for entry in entries {
/// if let Ok(entry) = entry {
/// // Here, `entry` is a `DirEntry`.
/// println!("{:?}", entry.file_name());
/// }
/// }
/// }
/// ```
#[stable(feature
=
"dir_entry_ext"
,
since
=
"1.1.0"
)]
pub
fn
file_name
(
&
self
)
->
OsString
{
self
.0
.file_name
()
...
...
src/libstd/sys/unix/ext/fs.rs
浏览文件 @
16699635
...
...
@@ -196,6 +196,22 @@ fn is_socket(&self) -> bool { self.as_inner().is(libc::S_IFSOCK) }
pub
trait
DirEntryExt
{
/// Returns the underlying `d_ino` field in the contained `dirent`
/// structure.
///
/// # Examples
///
/// ```
/// use std::fs;
/// use std::os::unix::fs::DirEntryExt;
///
/// if let Ok(entries) = fs::read_dir(".") {
/// for entry in entries {
/// if let Ok(entry) = entry {
/// // Here, `entry` is a `DirEntry`.
/// println!("{:?}: {}", entry.file_name(), entry.ino());
/// }
/// }
/// }
/// ```
#[stable(feature
=
"dir_entry_ext"
,
since
=
"1.1.0"
)]
fn
ino
(
&
self
)
->
u64
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录