Skip to content

Commit e7eef2a

Browse files
authored
Merge pull request #175 from zpg6/docs/writing-to-files-snippet-for-crate-doc
docs: adds same snippet of writing to files to `lib.rs` for crate doc
2 parents 6ebe113 + a9fd5a4 commit e7eef2a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@
4343
//! }
4444
//! ```
4545
//!
46+
//! For writing files:
47+
//!
48+
//! ```rust
49+
//! use embedded_sdmmc::{BlockDevice, Directory, Error, Mode, TimeSource};
50+
//! fn write_file<D: BlockDevice, T: TimeSource, const DIRS: usize, const FILES: usize, const VOLUMES: usize>(
51+
//! root_dir: &mut Directory<D, T, DIRS, FILES, VOLUMES>,
52+
//! ) -> Result<(), Error<D::Error>>
53+
//! {
54+
//! let my_other_file = root_dir.open_file_in_dir("MY_DATA.CSV", Mode::ReadWriteCreateOrAppend)?;
55+
//! my_other_file.write(b"Timestamp,Signal,Value\n")?;
56+
//! my_other_file.write(b"2025-01-01T00:00:00Z,TEMP,25.0\n")?;
57+
//! my_other_file.write(b"2025-01-01T00:00:01Z,TEMP,25.1\n")?;
58+
//! my_other_file.write(b"2025-01-01T00:00:02Z,TEMP,25.2\n")?;
59+
//! // Don't forget to flush the file so that the directory entry is updated
60+
//! my_other_file.flush()?;
61+
//! Ok(())
62+
//! }
63+
//! ```
64+
//!
4665
//! ## Features
4766
//!
4867
//! * `log`: Enabled by default. Generates log messages using the `log` crate.

0 commit comments

Comments
 (0)