pub struct Conin { /* private fields */ }
Expand description
Represents the input side of the tty/console terminal.
This is a singleton that aquires a lock to access the console (similiar to Stdin). It should be used to access the tty/terminal to avoid conflicts and other issues.
Implementations§
Source§impl Conin
impl Conin
Sourcepub fn lock<'a>(&self) -> ConsoleInLock<'a> ⓘ
pub fn lock<'a>(&self) -> ConsoleInLock<'a> ⓘ
Locks the input console and returns a guard.
Lock is released when the guard is dropped.
Sourcepub fn try_lock<'a>(&self) -> Option<ConsoleInLock<'a>>
pub fn try_lock<'a>(&self) -> Option<ConsoleInLock<'a>>
Tries to lock the input console and returns Some(guard) if it could or None if it could not. If the lock is already held by another thread then it will return None. Underlying lock is a ReentrantMutex from parking lot so will be fine to use on the same thread.
Lock is released when the guard is dropped.
Trait Implementations§
Source§impl ConsoleRead for Conin
impl ConsoleRead for Conin
Source§fn get_event_and_raw(
&mut self,
timeout: Option<Duration>,
) -> Option<Result<(Event, Vec<u8>)>>
fn get_event_and_raw( &mut self, timeout: Option<Duration>, ) -> Option<Result<(Event, Vec<u8>)>>
Get the next input event from the console and the bytes that define it.
If timeout is not None then will return a WouldBlock error after timeout
if no input.
Returns None if the Console has no more data vs a read that would block.
Source§fn poll(&mut self, timeout: Option<Duration>) -> bool
fn poll(&mut self, timeout: Option<Duration>) -> bool
Return when more data is avialable or timeout is reached.
If timeout is None will poll until data is available.
Returns true if more data was ready, false if timed out. Read more
Source§fn read_timeout(
&mut self,
buf: &mut [u8],
timeout: Option<Duration>,
) -> Result<usize>
fn read_timeout( &mut self, buf: &mut [u8], timeout: Option<Duration>, ) -> Result<usize>
Read data (like read) but with an optional timeout.
If timeout is None then block until there is something to read. If
timeout is a value then return after the timeout if nothing is available
to read.
Returns a Err of kind WouldBlock if it times out.
Source§impl Read for Conin
impl Read for Conin
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning
how many bytes were read. Read more
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
Reads all bytes until EOF in this source, placing them into
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Reads all bytes until EOF in this source, appending them to
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Reads the exact number of bytes required to fill
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Pull some bytes from this source into the specified buffer. Read more
Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Reads the exact number of bytes required to fill
cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Creates a “by reference” adaptor for this instance of
Read
. Read moreAuto Trait Implementations§
impl Freeze for Conin
impl !RefUnwindSafe for Conin
impl Send for Conin
impl Sync for Conin
impl Unpin for Conin
impl !UnwindSafe for Conin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<R> ConsoleReadExt for Rwhere
R: ConsoleRead,
impl<R> ConsoleReadExt for Rwhere
R: ConsoleRead,
Source§fn events_and_raw(self) -> EventsAndRaw<R> ⓘ
fn events_and_raw(self) -> EventsAndRaw<R> ⓘ
An iterator over input events and the raw bytes that make them.
Source§fn get_event(&mut self) -> Option<Result<Event, Error>>
fn get_event(&mut self) -> Option<Result<Event, Error>>
Get the next input event from the console.
This version will block until an event is ready.
Returns None if the Console has no more data vs a read that would block.