Skip to content

Commit

Permalink
Make toml optional
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Feb 24, 2024
1 parent 0113512 commit b961a1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cargo-espflash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,28 @@ pub enum Error {
}

/// TOML deserialization error
#[cfg(feature = "cli")]
#[derive(Debug)]
pub struct TomlError {
err: toml::de::Error,
source: String,
}

#[cfg(feature = "cli")]
impl TomlError {
pub fn new(err: toml::de::Error, source: String) -> Self {
Self { err, source }
}
}

#[cfg(feature = "cli")]
impl Display for TomlError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "Failed to parse toml")
}
}

#[cfg(feature = "cli")]
impl Diagnostic for TomlError {
fn source_code(&self) -> Option<&dyn SourceCode> {
Some(&self.source)
Expand All @@ -92,6 +96,7 @@ impl Diagnostic for TomlError {
}

// NOTE: no `source` on purpose to prevent duplicating the message
#[cfg(feature = "cli")]
impl std::error::Error for TomlError {}

/// Unsupported target error
Expand Down
5 changes: 3 additions & 2 deletions espflash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ sha2 = "0.10.8"
slip-codec = { version = "0.4.0", optional = true }
strum = { version = "0.26.1", features = ["derive"], optional = true }
thiserror = "1.0.56"
toml = "0.8.10"
toml = { version = "0.8.10", optional = true }
update-informer = { version = "1.1.0", optional = true }
xmas-elf = { version = "0.9.1", optional = true }

Expand All @@ -78,6 +78,7 @@ cli = [
"dep:indicatif",
"dep:lazy_static",
"dep:parse_int",
"dep:toml",
"dep:update-informer",
"serialport"
]
Expand All @@ -86,4 +87,4 @@ cli = [
serialport = ["flashing", "dep:serialport", "dep:slip-codec", "dep:regex", "dep:strum"]

# enables flash stubs and stub commands
flashing = ["xmas-elf"]
flashing = ["xmas-elf", "dep:toml"]

0 comments on commit b961a1b

Please sign in to comment.