summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Porte <microjoe@microjoe.org>2020-02-27 12:51:56 +0100
committerRomain Porte <microjoe@microjoe.org>2020-02-27 12:51:56 +0100
commit5026b558ff56d25a6fb93abeec7580ab90f79e67 (patch)
tree6dba0fccd740e5c3a37eb1f6f7a0ae0bf14475ca
parent140e1f489d24b62f86c0f0376b8d0db738eead6a (diff)
downloadcharlcd-5026b558ff56d25a6fb93abeec7580ab90f79e67.tar.gz
charlcd-5026b558ff56d25a6fb93abeec7580ab90f79e67.zip
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.
-rw-r--r--src/lib.rs45
1 files 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<T> {
@@ -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<BufWriter<File>>;
+pub type FileScreen = Screen<BufWriter<File>>;
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