// /std/src/io/stdio.rs
pub struct StdinLock<'a> {
inner: MutexGuard<'a, BufReader<StdinRaw>>,
}
impl Stdin {
pub fn lock(&self) -> StdinLock<'static> {
// Locks this handle with 'static lifetime. This depends on the
// implementation detail that the underlying `Mutex` is static.
StdinLock { inner: self.inner.lock().unwrap_or_else(|e| e.into_inner()) }
}
}
Since we only have one stdin instance in a process, why does not Stdin::lock
just return a owned StdinLock
with MutexGuard<'static, ...>
instead?
New contributor
Fachep is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.