Struct StdinLock
#[must_use = "if unused stdin will immediately unlock"]
pub struct StdinLock<'a> { pub(in ::io::stdio) inner: MutexGuard<'a, BufReader<StdinRaw>> }
A locked reference to the Stdin handle.
This handle implements both the Read and BufRead traits, and
is constructed via the Stdin::lock method.
Note: Windows Portability Considerations
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.
Examples
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(())
}
Fields
inner: MutexGuard<'a, BufReader<StdinRaw>>
Implementations
impl StdinLock<'_>
fn as_mut_buf(&mut self) -> &mut BufReader<impl Read>
Trait Implementations
impl BufRead for StdinLock<'_>
fn fill_buf(&mut self) -> Result<&[u8]>fn consume(&mut self, n: usize)fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize>fn read_line(&mut self, buf: &mut String) -> Result<usize>
impl CopyRead for StdinLock<'_>
fn drain_to<W: Write>(&mut self, writer: &mut W, outer_limit: u64) -> Result<u64>fn properties(&self) -> CopyParams
impl Debug for StdinLock<'_>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl IsTerminal for StdinLock<'_>
fn is_terminal(&self) -> bool
impl Read for StdinLock<'_>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<()>fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>fn is_read_vectored(&self) -> boolfn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>fn read_to_string(&mut self, buf: &mut String) -> Result<usize>fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_, u8>) -> Result<()>
impl SpecCopy for StdinLock<'_>
fn copy<R: Read + ?Sized, W: Write + ?Sized>(read: &mut R, write: &mut W) -> Result<CopyState>
impl SpecReadByte for StdinLock<'_>
fn spec_read_byte(&mut self) -> Option<Result<u8>>
impl StdioExt for StdinLock<'_>
fn set_fd<T: Into<OwnedFd>>(&mut self, fd: T) -> Result<()>fn take_fd(&mut self) -> Result<OwnedFd>fn replace_fd<T: Into<OwnedFd>>(&mut self, replace_with: T) -> Result<OwnedFd>
impl StdioExt for StdinLock<'_>
fn set_handle<T: Into<OwnedHandle>>(&mut self, handle: Option<T>) -> Result<()>fn replace_handle<T: Into<OwnedHandle>>(&mut self, replace_with: T) -> Result<Option<BorrowedHandle<'static>>>fn take_handle(&mut self) -> Result<Option<BorrowedHandle<'static>>>
impl<'a> AsFd for StdinLock<'a>
fn as_fd(&self) -> BorrowedFd<'_>
impl<'a> AsHandle for StdinLock<'a>
fn as_handle(&self) -> BorrowedHandle<'_>
impl<'a> AsRawFd for StdinLock<'a>
fn as_raw_fd(&self) -> RawFd
impl<'a> AsRawHandle for StdinLock<'a>
fn as_raw_handle(&self) -> RawHandle
Auto Trait Implementations
impl<'a> !Send for StdinLock<'a>
impl<'a> Freeze for StdinLock<'a>
impl<'a> RefUnwindSafe for StdinLock<'a>
impl<'a> Sync for StdinLock<'a>
impl<'a> Unpin for StdinLock<'a>
impl<'a> UnsafeUnpin for StdinLock<'a>
impl<'a> UnwindSafe for StdinLock<'a>
Blanket Implementations
impl<R> SpecReadByte for StdinLock<'a>
where
R: Read,
fn spec_read_byte(&mut self) -> Option<Result<u8, Error>>
impl<T> Any for StdinLock<'a>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for StdinLock<'a>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for StdinLock<'a>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for StdinLock<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for StdinLock<'a>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for StdinLock<'a>
impl<T, U> Into<U> for StdinLock<'a>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for StdinLock<'a>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for StdinLock<'a>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>