pub struct StdinLock<'a> { /* private fields */ }
A locked reference to the Stdin handle.
This handle implements both the Read and BufRead traits, and is constructed via the Stdin::lock method.
When operating in a console, the Windows implementation of this stream does not support non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return an error.
In a process with a detached console, such as one using #![windows_subsystem = "windows"], or in a child process spawned from such a process, the contained handle will be null. In such cases, the standard library’s Read and Write will do nothing and silently succeed. All other I/O operations, via the standard library or via raw Windows API calls, will fail.
use std::io::{self, BufRead};
fn main() -> io::Result<()> {
let mut buffer = String::new();
let stdin = io::stdin(); // We get `Stdin` here.
{
let mut handle = stdin.lock(); // We get `StdinLock` here.
handle.read_line(&mut buffer)?;
} // `StdinLock` is dropped here.
Ok(())
}impl<'a> AsFd for StdinLock<'a>Available on Unix or HermitCore or target_os=trusty or WASI or target_os=motor only.
impl<'a> AsHandle for StdinLock<'a>Available on Windows only.
impl<'a> AsRawFd for StdinLock<'a>Available on (Unix or HermitCore or target_os=trusty or WASI or target_os=motor) and non-target_os=trusty only.
impl<'a> AsRawHandle for StdinLock<'a>Available on Windows only.
impl BufRead for StdinLock<'_>
fn fill_buf(&mut self) -> Result<&[u8]>
Read methods, if empty. Read more
fn consume(&mut self, n: usize)
amount of additional bytes from the internal buffer as having been read. Subsequent calls to read only return bytes that have not been marked as read. Read more
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize>
fn read_line(&mut self, buf: &mut String) -> Result<usize>
0xA byte) is reached, and append them to the provided String buffer. Read more
fn has_data_left(&mut self) -> Result<bool>
buf_read_has_data_left #86423)
read. Read more
fn skip_until(&mut self, byte: u8) -> Result<usize>
byte or EOF is reached. Read more
fn split(self, byte: u8) -> Split<Self> ⓘwhere
Self: Sized,byte. Read more
fn lines(self) -> Lines<Self> ⓘwhere
Self: Sized,impl Debug for StdinLock<'_>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl IsTerminal for StdinLock<'_>
fn is_terminal(&self) -> bool
true if the descriptor/handle refers to a terminal/tty. Read more
impl Read for StdinLock<'_>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<()>
read_buf #78485)
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read, except that it reads into a slice of buffers. Read more
fn is_read_vectored(&self) -> bool
can_vector #69941)
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf. Read more
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf. Read more
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf. Read more
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<()>
read_buf #78485)
cursor. Read more
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,Read. Read more
fn bytes(self) -> Bytes<Self> ⓘwhere
Self: Sized,fn chain<R: Read>(self, next: R) -> Chain<Self, R> ⓘwhere
Self: Sized,fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,limit bytes from it. Read more
fn read_array<const N: usize>(&mut self) -> Result<[u8; N]>where
Self: Sized,read_array #148848)
impl<'a> Freeze for StdinLock<'a>
impl<'a> RefUnwindSafe for StdinLock<'a>
impl<'a> !Send for StdinLock<'a>
impl<'a> Sync for StdinLock<'a>
impl<'a> Unpin for StdinLock<'a>
impl<'a> UnwindSafe for StdinLock<'a>
impl<T> Any for Twhere
T: 'static + ?Sized,impl<T> Borrow<T> for Twhere
T: ?Sized,impl<T> BorrowMut<T> for Twhere
T: ?Sized,impl<T> From<T> for T
fn from(t: T) -> T
Returns the argument unchanged.
impl<T, U> Into<U> for Twhere
U: From<T>,fn into(self) -> U
Calls U::from(self).
That is, this conversion is whatever the implementation of From<T> for U chooses to do.
impl<T, U> TryFrom<U> for Twhere
U: Into<T>,type Error = Infallible
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/io/struct.StdinLock.html