Struct std::io::StdinLock1.0.0[][src]

pub struct StdinLock<'a> { /* fields omitted */ }
Expand description

Stdin 句柄的锁定引用。

该句柄同时实现 ReadBufRead traits,并通过 Stdin::lock 方法构造。

Note: Windows 可移植性注意事项

在控制台中操作时,此流的 Windows 实现不支持非 UTF-8 字节序列。 尝试读取无效的 UTF-8 字节将返回错误。

Examples

use std::io::{self, BufRead};

fn main() -> io::Result<()> {
    let mut buffer = String::new();
    let stdin = io::stdin(); // 我们在这里得到 `Stdin`。
    {
        let mut handle = stdin.lock(); // 我们在这里得到 `StdinLock`。
        handle.read_line(&mut buffer)?;
    } // `StdinLock` 被丢弃在这里。
    Ok(())
}
Run

Trait Implementations

🔬 This is a nightly-only experimental API. (io_safety #87074)
This is supported on Unix only.

借用文件描述符。 Read more

🔬 This is a nightly-only experimental API. (io_safety #87074)

借用句柄。 Read more

This is supported on Unix only.

提取原始文件描述符。 Read more

提取原始句柄,无需任何所有权。

返回内部缓冲区的内容,如果内部缓冲区为空,则使用内部 reader 中的更多数据填充内部缓冲区。 Read more

告诉此缓冲区 amt 字节已从缓冲区中消耗掉,因此在调用 read 时不再应返回它们。 Read more

将所有字节读入 buf,直到到达定界符 byte 或 EOF。 Read more

读取所有字节,直到到达换行符 (0xA 字节),然后将它们追加到提供的缓冲区中。 Read more

🔬 This is a nightly-only experimental API. (buf_read_has_data_left #86423)

检查底层 Read 是否有任何数据可供读取。 Read more

返回对该字节 byte 上的 reader 拆分内容的迭代器。 Read more

返回此 reader 的各行上的迭代器。 Read more

使用给定的格式化程序格式化该值。 Read more

从该源中提取一些字节到指定的缓冲区中,返回读取的字节数。 Read more

read 相似,不同之处在于它读入缓冲区的一部分。 Read more

🔬 This is a nightly-only experimental API. (can_vector #69941)

确定此 Read 是否具有有效的 read_vectored 实现。 Read more

读取所有字节,直到此源中的 EOF 为止,然后将它们放入 bufRead more

读取这个源中的所有字节,直到 EOF 为止,然后将它们追加到 bufRead more

读取填充 buf 所需的确切字节数。 Read more

🔬 This is a nightly-only experimental API. (read_buf #78485)

从此源中提取一些字节到指定的缓冲区中。 Read more

🔬 This is a nightly-only experimental API. (read_buf #78485)

读取填充 buf 所需的确切字节数。 Read more

为这个 Read 实例创建一个 “by reference” 适配器。 Read more

将此 Read 实例的字节数转换为 IteratorRead more

创建一个适配器,将这个流与另一个链接起来。 Read more

创建一个适配器,最多从中读取 limit 个字节。 Read more

Auto Trait Implementations

Blanket Implementations

获取 selfTypeIdRead more

从拥有的值中一成不变地借用。 Read more

从拥有的值中借用。 Read more

执行转换。

执行转换。

发生转换错误时返回的类型。

执行转换。

发生转换错误时返回的类型。

执行转换。