Skip to content

Commit 95a47b8

Browse files
committed
Make publicly exported types implement Debug trait
It seems to have become common practice for publicly exported types in a library to implement the Debug trait. Doing so potentially simplifies trouble shooting in client code directly but it also is a requirement in case said client code embeds such objects and wants the wrappers to implement this trait. For a deeper discussion of this topic please refer to rust-lang/rust#32054 To that end, this change adjust all publicly exported types to derive from Debug. It also adds a crate wide lint enforcing this constraint.
1 parent 5c95c22 commit 95a47b8

File tree

8 files changed

+40
-11
lines changed

8 files changed

+40
-11
lines changed

src/async.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn async_stdin() -> AsyncReader {
3030
///
3131
/// This acts as any other stream, with the exception that reading from it won't block. Instead,
3232
/// the buffer will only be partially updated based on how much the internal buffer holds.
33+
#[derive(Debug)]
3334
pub struct AsyncReader {
3435
/// The underlying mpsc receiver.
3536
recv: mpsc::Receiver<io::Result<u8>>,

src/cursor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ derive_csi_sequence!("Save the cursor.", Save, "s");
2929
/// print!("{}{}Stuff", termion::clear::All, termion::cursor::Goto(5, 3));
3030
/// }
3131
/// ```
32-
#[derive(Copy, Clone, PartialEq, Eq)]
32+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
3333
pub struct Goto(pub u16, pub u16);
3434

3535
impl Default for Goto {
@@ -47,7 +47,7 @@ impl fmt::Display for Goto {
4747
}
4848

4949
/// Move cursor left.
50-
#[derive(Copy, Clone, PartialEq, Eq)]
50+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
5151
pub struct Left(pub u16);
5252

5353
impl fmt::Display for Left {
@@ -57,7 +57,7 @@ impl fmt::Display for Left {
5757
}
5858

5959
/// Move cursor right.
60-
#[derive(Copy, Clone, PartialEq, Eq)]
60+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6161
pub struct Right(pub u16);
6262

6363
impl fmt::Display for Right {
@@ -67,7 +67,7 @@ impl fmt::Display for Right {
6767
}
6868

6969
/// Move cursor up.
70-
#[derive(Copy, Clone, PartialEq, Eq)]
70+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
7171
pub struct Up(pub u16);
7272

7373
impl fmt::Display for Up {
@@ -77,7 +77,7 @@ impl fmt::Display for Up {
7777
}
7878

7979
/// Move cursor down.
80-
#[derive(Copy, Clone, PartialEq, Eq)]
80+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
8181
pub struct Down(pub u16);
8282

8383
impl fmt::Display for Down {

src/input.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use event::{self, Event, Key};
77
use raw::IntoRawMode;
88

99
/// An iterator over input keys.
10+
#[derive(Debug)]
1011
pub struct Keys<R> {
1112
iter: Events<R>,
1213
}
@@ -27,6 +28,7 @@ impl<R: Read> Iterator for Keys<R> {
2728
}
2829

2930
/// An iterator over input events.
31+
#[derive(Debug)]
3032
pub struct Events<R> {
3133
inner: EventsAndRaw<R>
3234
}
@@ -40,6 +42,7 @@ impl<R: Read> Iterator for Events<R> {
4042
}
4143

4244
/// An iterator over input events and the bytes that define them.
45+
#[derive(Debug)]
4346
pub struct EventsAndRaw<R> {
4447
source: R,
4548
leftover: Option<u8>,
@@ -182,6 +185,7 @@ const EXIT_MOUSE_SEQUENCE: &'static str = csi!("?1006l\x1b[?1015l\x1b[?1002l\x1b
182185
/// A terminal with added mouse support.
183186
///
184187
/// This can be obtained through the `From` implementations.
188+
#[derive(Debug)]
185189
pub struct MouseTerminal<W: Write> {
186190
term: W,
187191
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! Supports Redox, Mac OS X, and Linux (or, in general, ANSI terminals).
1010
//!
1111
//! For more information refer to the [README](https://github.com/ticki/termion).
12+
#![deny(missing_debug_implementations)]
1213
#![warn(missing_docs)]
1314

1415
#[cfg(target_os = "redox")]

src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ macro_rules! csi {
77
macro_rules! derive_csi_sequence {
88
($doc:expr, $name:ident, $value:expr) => {
99
#[doc = $doc]
10-
#[derive(Copy, Clone)]
10+
#[derive(Copy, Clone, Debug)]
1111
pub struct $name;
1212

1313
impl fmt::Display for $name {

src/raw.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,47 @@
2222
//! }
2323
//! ```
2424
25+
use std::fmt;
2526
use std::io::{self, Write};
2627
use std::ops;
2728

28-
use sys::Termios;
29+
use sys::Termios as SysTermios;
2930
use sys::attr::{get_terminal_attr, raw_terminal_attr, set_terminal_attr};
3031

3132
/// The timeout of an escape code control sequence, in milliseconds.
3233
pub const CONTROL_SEQUENCE_TIMEOUT: u64 = 100;
3334

35+
/// A wrapper around sys::Termios that implements std::fmt::Debug.
36+
struct Termios(SysTermios);
37+
38+
impl fmt::Debug for Termios {
39+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40+
write!(f, "termion::sys::Termios")
41+
}
42+
}
43+
44+
impl ops::Deref for Termios {
45+
type Target = SysTermios;
46+
47+
fn deref(&self) -> &SysTermios {
48+
&self.0
49+
}
50+
51+
}
52+
3453
/// A terminal restorer, which keeps the previous state of the terminal, and restores it, when
3554
/// dropped.
3655
///
3756
/// Restoring will entirely bring back the old TTY state.
57+
#[derive(Debug)]
3858
pub struct RawTerminal<W: Write> {
3959
prev_ios: Termios,
4060
output: W,
4161
}
4262

4363
impl<W: Write> Drop for RawTerminal<W> {
4464
fn drop(&mut self) {
45-
set_terminal_attr(&self.prev_ios).unwrap();
65+
set_terminal_attr(&*self.prev_ios).unwrap();
4666
}
4767
}
4868

@@ -95,7 +115,7 @@ impl<W: Write> IntoRawMode for W {
95115
set_terminal_attr(&ios)?;
96116

97117
Ok(RawTerminal {
98-
prev_ios: prev_ios,
118+
prev_ios: Termios(prev_ios),
99119
output: self,
100120
})
101121
}

src/screen.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use std::ops;
2424
use std::fmt;
2525

2626
/// Switch to the main screen buffer of the terminal.
27+
#[derive(Debug)]
2728
pub struct ToMainScreen;
2829

2930
impl fmt::Display for ToMainScreen {
@@ -33,6 +34,7 @@ impl fmt::Display for ToMainScreen {
3334
}
3435

3536
/// Switch to the alternate screen buffer of the terminal.
37+
#[derive(Debug)]
3638
pub struct ToAlternateScreen;
3739

3840
impl fmt::Display for ToAlternateScreen {
@@ -46,6 +48,7 @@ impl fmt::Display for ToAlternateScreen {
4648
///
4749
/// This is achieved by switching the terminal to the alternate screen on creation and
4850
/// automatically switching it back to the original screen on drop.
51+
#[derive(Debug)]
4952
pub struct AlternateScreen<W: Write> {
5053
/// The output target.
5154
output: W,

src/scroll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::fmt;
44

55
/// Scroll up.
6-
#[derive(Copy, Clone, PartialEq, Eq)]
6+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
77
pub struct Up(pub u16);
88

99
impl fmt::Display for Up {
@@ -13,7 +13,7 @@ impl fmt::Display for Up {
1313
}
1414

1515
/// Scroll down.
16-
#[derive(Copy, Clone, PartialEq, Eq)]
16+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1717
pub struct Down(pub u16);
1818

1919
impl fmt::Display for Down {

0 commit comments

Comments
 (0)