Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indicate which types/functions/etc. require the std feature in the docs #10

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ license = "MIT OR Apache-2.0"
keywords = ["esp-idf", "partition", "partition-table"]
categories = ["embedded", "parsing"]

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
csv = { version = "1.1.6", optional = true }
deku = { version = "0.15.1", optional = true }
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,25 @@ pub enum Error {

/// An error which originated in the `csv` package
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[cfg_attr(feature = "std", error(transparent))]
CsvError(#[from] csv::Error),

/// An error which originated in the `deku` package
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[cfg_attr(feature = "std", error(transparent))]
DekuError(#[from] deku::DekuError),

/// An error which occurred while trying to convert bytes to a String
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[cfg_attr(feature = "std", error(transparent))]
FromUtf8Error(#[from] std::string::FromUtf8Error),

/// An error which originated in the `std::io` module
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[cfg_attr(feature = "std", error(transparent))]
IoError(#[from] std::io::Error),
}
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html>

#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]

#[cfg(feature = "std")]
use core::ops::Rem;
Expand Down Expand Up @@ -60,6 +61,7 @@ impl PartitionTable {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
/// Attempt to parse either a binary or CSV partition table from the given
/// input.
///
Expand All @@ -84,6 +86,7 @@ impl PartitionTable {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
/// Attempt to parse a binary partition table from the given bytes.
///
/// For more information on the partition table format see:
Expand Down Expand Up @@ -136,6 +139,7 @@ impl PartitionTable {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
/// Attempt to parse a CSV partition table from the given string.
///
/// For more information on the partition table format see:
Expand Down Expand Up @@ -196,6 +200,7 @@ impl PartitionTable {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
/// Convert a partition table to binary
pub fn to_bin(&self) -> Result<Vec<u8>, Error> {
let mut result = Vec::with_capacity(PARTITION_TABLE_SIZE);
Expand All @@ -221,6 +226,7 @@ impl PartitionTable {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
/// Convert a partition table to a CSV string
pub fn to_csv(&self) -> Result<String, Error> {
let mut csv = String::new();
Expand All @@ -246,6 +252,7 @@ impl PartitionTable {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
/// Validate a partition table
fn validate(&self) -> Result<(), Error> {
// There must be at least one partition with type 'app'
Expand Down
3 changes: 3 additions & 0 deletions src/partition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl Type {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
/// Return a `String` stating which subtypes are allowed for the given type.
///
/// This is useful for error handling in dependent packages.
Expand Down Expand Up @@ -309,6 +310,7 @@ impl Partition {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
/// Write a record to the provided binary writer
pub fn write_bin<W>(&self, writer: &mut W) -> std::io::Result<()>
where
Expand All @@ -331,6 +333,7 @@ impl Partition {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
/// Write a record to the provided [`csv::Writer`]
pub fn write_csv<W>(&self, csv: &mut csv::Writer<W>) -> std::io::Result<()>
where
Expand Down