From 9df0a6e9061d65220df91578e7442a75a9727361 Mon Sep 17 00:00:00 2001 From: Agathe Porte Date: Thu, 27 Feb 2020 12:51:56 +0100 Subject: lib: make the doctest pass Not very happy with the provided examples, because we need to use the FileScreen::default for the examples to work instead of the Screen::default that works in the examples. To be retried on nightly and maybe file up a bug report. --- src/lib.rs | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 49a32b0..0eacbfc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,16 +22,21 @@ use codes::WriteInto; /// /// # Simple example /// -/// ```rust +/// ```no_run +/// extern crate charlcd; +/// /// use charlcd::Screen; +/// use std::io::Write; /// /// fn main() -> std::io::Result<()> { -/// let mut screen = Screen::default(); // will use "/dev/lcd" charlcd driver +/// let mut screen = Screen::default()?; // will use "/dev/lcd" charlcd driver /// /// screen.clear()?; /// screen.write(b"hello, world!")?; /// screen.flash_backlight()?; /// screen.flush()?; // send all the previous commands to the driver at once +/// +/// Ok(()) /// } /// ``` pub struct Screen { @@ -330,7 +335,7 @@ where // Concrete screen based on a File, to write to the real charlcd driver (or to // another file). -type FileScreen = Screen>; +pub type FileScreen = Screen>; const DEFAULT_SCREEN_DEV_PATH: &str = "/dev/lcd"; @@ -352,10 +357,19 @@ impl FileScreen { /// /// # Example /// - /// ```rust - /// let screen = Screen::default()?; // the screen is 20x4 in this test - /// let width = screen.width()?; - /// assert_eq!(width, 20); + /// ```no_run + /// extern crate charlcd; + /// + /// use charlcd::FileScreen; + /// + /// fn main() -> std::io::Result<()> { + /// let screen = FileScreen::default()?; // the screen is 20x4 in this test + /// + /// let width = screen.width()?; + /// assert_eq!(width, 20); + /// + /// Ok(()) + /// } /// ``` /// /// # Important note @@ -378,10 +392,19 @@ impl FileScreen { /// /// # Example /// - /// ```rust - /// let screen = Screen::default()?; // the screen is 20x4 in this test - /// let width = screen.height()?; - /// assert_eq!(width, 4); + /// ```no_run + /// extern crate charlcd; + /// + /// use charlcd::FileScreen; + /// + /// fn main() -> std::io::Result<()> { + /// let screen = FileScreen::default()?; // the screen is 20x4 in this test + /// + /// let height = screen.height()?; + /// assert_eq!(height, 4); + /// + /// Ok(()) + /// } /// ``` /// /// # Important note -- cgit v1.2.3