Skip to content

Add feature flag for defmt derives for errors #773

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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ edition = "2021"
[features]
default = ["std", "derive"]
std = ["alloc", "serde?/std"]
alloc = ["serde?/alloc"]
alloc = ["serde?/alloc", "defmt?/alloc"]
derive = ["bincode_derive"]
defmt = ["dep:defmt"]

[dependencies]
bincode_derive = { path = "derive", version = "2.0.1", optional = true }
defmt = {version = "1.0.1", optional = true}
serde = { version = "1.0", default-features = false, optional = true }
unty = "0.0.4"

Expand Down
9 changes: 9 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// Errors that can be encountered by encoding a type
#[non_exhaustive]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]

Check failure on line 6 in src/error.rs

View workflow job for this annotation

GitHub Actions / Check (stable)

the trait bound `serde::EncodeError: Format` is not satisfied

Check failure on line 6 in src/error.rs

View workflow job for this annotation

GitHub Actions / Check (1.85.0)

the trait bound `serde::EncodeError: Format` is not satisfied

Check failure on line 6 in src/error.rs

View workflow job for this annotation

GitHub Actions / Check (beta)

the trait bound `serde::EncodeError: Format` is not satisfied

Check failure on line 6 in src/error.rs

View workflow job for this annotation

GitHub Actions / Lints

the trait bound `features::serde::EncodeError: defmt::Format` is not satisfied

Check failure on line 6 in src/error.rs

View workflow job for this annotation

GitHub Actions / Check (nightly)

the trait bound `serde::EncodeError: Format` is not satisfied
pub enum EncodeError {
/// The writer ran out of storage.
UnexpectedEnd,
Expand Down Expand Up @@ -30,6 +31,7 @@
#[cfg(feature = "std")]
Io {
/// The encountered error
#[cfg_attr(feature = "defmt", defmt(Debug2Format))]
inner: std::io::Error,
/// The amount of bytes that were written before the error occurred
index: usize,
Expand All @@ -46,8 +48,10 @@
#[cfg(feature = "std")]
InvalidSystemTime {
/// The error that was thrown by the SystemTime
#[cfg_attr(feature = "defmt", defmt(Debug2Format))]
inner: std::time::SystemTimeError,
/// The SystemTime that caused the error
#[cfg_attr(feature = "defmt", defmt(Debug2Format))]
time: std::boxed::Box<std::time::SystemTime>,
},

Expand All @@ -65,6 +69,7 @@

/// Errors that can be encountered by decoding a type
#[non_exhaustive]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]

Check failure on line 72 in src/error.rs

View workflow job for this annotation

GitHub Actions / Check (stable)

the trait bound `serde::DecodeError: Format` is not satisfied

Check failure on line 72 in src/error.rs

View workflow job for this annotation

GitHub Actions / Check (1.85.0)

the trait bound `serde::DecodeError: Format` is not satisfied

Check failure on line 72 in src/error.rs

View workflow job for this annotation

GitHub Actions / Check (beta)

the trait bound `serde::DecodeError: Format` is not satisfied

Check failure on line 72 in src/error.rs

View workflow job for this annotation

GitHub Actions / Lints

the trait bound `features::serde::DecodeError: defmt::Format` is not satisfied

Check failure on line 72 in src/error.rs

View workflow job for this annotation

GitHub Actions / Check (nightly)

the trait bound `serde::DecodeError: Format` is not satisfied
#[derive(Debug)]
pub enum DecodeError {
/// The reader reached its end but more bytes were expected.
Expand Down Expand Up @@ -109,6 +114,7 @@
/// The decoder tried to decode a `str`, but an utf8 error was encountered.
Utf8 {
/// The inner error
#[cfg_attr(feature = "defmt", defmt(Debug2Format))]
inner: core::str::Utf8Error,
},

Expand Down Expand Up @@ -168,6 +174,7 @@
#[cfg(feature = "std")]
Io {
/// The IO error expected
#[cfg_attr(feature = "defmt", defmt(Debug2Format))]
inner: std::io::Error,

/// Gives an estimate of how many extra bytes are needed.
Expand Down Expand Up @@ -217,6 +224,7 @@
/// Indicates which enum variants are allowed
#[non_exhaustive]
#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum AllowedEnumVariants {
/// All values between `min` and `max` (inclusive) are allowed
#[allow(missing_docs)]
Expand All @@ -229,6 +237,7 @@
#[non_exhaustive]
#[derive(Debug, PartialEq, Eq)]
#[allow(missing_docs)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum IntegerType {
U8,
U16,
Expand Down
Loading