From fe90d952bf9d6e0549a1389e87455be636cfffef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Wed, 20 Jun 2018 19:52:18 +0200 Subject: [PATCH] Fix doc-tests --- src/lib.rs | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cc0ffcf..82a2386 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,27 +18,37 @@ //! //! # Examples //! -//! Initialize a filesystem object (note: `fscommon` crate is used to speedup IO operations): //! ```rust -//! let img_file = File::open("fat.img")?; -//! let buf_stream = fscommon::BufStream::new(img_file); -//! let fs = fatfs::FileSystem::new(buf_stream, fatfs::FsOptions::new())?; -//! ``` -//! Write a file: -//! ```rust -//! let root_dir = fs.root_dir(); -//! root_dir.create_dir("foo/bar")?; -//! let mut file = root_dir.create_file("foo/bar/hello.txt")?; -//! file.truncate()?; -//! file.write_all(b"Hello World!")?; -//! ``` -//! Read a directory: -//! ```rust -//! let root_dir = fs.root_dir(); -//! let dir = root_dir.open_dir("foo/bar")?; -//! for r in dir.iter()? { -//! let entry = r?; -//! println!(entry.file_name()); +//! // Declare external crates +//! // Note: `fscommon` crate is used to speedup IO operations +//! extern crate fatfs; +//! extern crate fscommon; +//! +//! use std::io::prelude::*; +//! +//! fn main() -> std::io::Result<()> { +//! # std::fs::copy("resources/fat16.img", "tmp/fat.img")?; +//! // Initialize a filesystem object +//! let img_file = std::fs::OpenOptions::new().read(true).write(true) +//! .open("tmp/fat.img")?; +//! let buf_stream = fscommon::BufStream::new(img_file); +//! let fs = fatfs::FileSystem::new(buf_stream, fatfs::FsOptions::new())?; +//! let root_dir = fs.root_dir(); +//! +//! // Write a file +//! root_dir.create_dir("foo")?; +//! let mut file = root_dir.create_file("foo/hello.txt")?; +//! file.truncate()?; +//! file.write_all(b"Hello World!")?; +//! +//! // Read a directory +//! let dir = root_dir.open_dir("foo")?; +//! for r in dir.iter() { +//! let entry = r?; +//! println!("{}", entry.file_name()); +//! } +//! # std::fs::remove_file("tmp/fat.img")?; +//! # Ok(()) //! } //! ```