From bead64f9498f2787fb1d5aa247d79536f2424528 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 14 Dec 2021 16:46:19 -0500 Subject: clippy --- src/output.rs | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'src/output.rs') diff --git a/src/output.rs b/src/output.rs index 7669f4c..9b72438 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,5 +1,3 @@ -use crate::error::*; - use futures_lite::io::AsyncWriteExt as _; use crate::private::Output as _; @@ -14,7 +12,10 @@ impl ScreenGuard { /// Switches the terminal on `stdout` to alternate screen mode and returns /// a guard object. This is typically called as part of /// [`Output::new`](Output::new). - pub async fn new() -> Result { + /// + /// # Errors + /// * `Error::WriteStdout`: failed to write initialization to stdout + pub async fn new() -> crate::error::Result { write_stdout( &mut blocking::Unblock::new(std::io::stdout()), crate::INIT, @@ -24,7 +25,10 @@ impl ScreenGuard { } /// Switch back from alternate screen mode early. - pub async fn cleanup(&mut self) -> Result<()> { + /// + /// # Errors + /// * `Error::WriteStdout`: failed to write deinitialization to stdout + pub async fn cleanup(&mut self) -> crate::error::Result<()> { if self.cleaned_up { return Ok(()); } @@ -43,6 +47,8 @@ impl Drop for ScreenGuard { /// call `cleanup` manually instead. fn drop(&mut self) { futures_lite::future::block_on(async { + // https://github.com/rust-lang/rust-clippy/issues/8003 + #[allow(clippy::let_underscore_drop)] let _ = self.cleanup().await; }); } @@ -85,7 +91,10 @@ impl crate::Textmode for Output {} impl Output { /// Creates a new `Output` instance containing a /// [`ScreenGuard`](ScreenGuard) instance. - pub async fn new() -> Result { + /// + /// # Errors + /// * `Error::WriteStdout`: failed to write initialization to stdout + pub async fn new() -> crate::error::Result { let mut self_ = Self::new_without_screen(); self_.screen = Some(ScreenGuard::new().await?); Ok(self_) @@ -93,6 +102,7 @@ impl Output { /// Creates a new `Output` instance without creating a /// [`ScreenGuard`](ScreenGuard) instance. + #[must_use] pub fn new_without_screen() -> Self { let (rows, cols) = match terminal_size::terminal_size() { Some((terminal_size::Width(w), terminal_size::Height(h))) => { @@ -121,7 +131,10 @@ impl Output { /// Draws the in-memory screen to the terminal on `stdout`. This is done /// using a diff mechanism to only update the parts of the terminal which /// are different from the in-memory screen. - pub async fn refresh(&mut self) -> Result<()> { + /// + /// # Errors + /// * `Error::WriteStdout`: failed to write screen state to stdout + pub async fn refresh(&mut self) -> crate::error::Result<()> { let diff = self.next().screen().state_diff(self.cur().screen()); write_stdout(&mut self.stdout, &diff).await?; self.cur_mut().process(&diff); @@ -133,7 +146,10 @@ impl Output { /// mechanism like `refresh`. This can be useful when the current state of /// the terminal screen is unknown, such as after the terminal has been /// resized. - pub async fn hard_refresh(&mut self) -> Result<()> { + /// + /// # Errors + /// * `Error::WriteStdout`: failed to write screen state to stdout + pub async fn hard_refresh(&mut self) -> crate::error::Result<()> { let contents = self.next().screen().state_formatted(); write_stdout(&mut self.stdout, &contents).await?; self.cur_mut().process(&contents); @@ -144,8 +160,14 @@ impl Output { async fn write_stdout( stdout: &mut blocking::Unblock, buf: &[u8], -) -> Result<()> { - stdout.write_all(buf).await.map_err(Error::WriteStdout)?; - stdout.flush().await.map_err(Error::WriteStdout)?; +) -> crate::error::Result<()> { + stdout + .write_all(buf) + .await + .map_err(crate::error::Error::WriteStdout)?; + stdout + .flush() + .await + .map_err(crate::error::Error::WriteStdout)?; Ok(()) } -- cgit v1.2.3-54-g00ecf