From a1f82aa7e1db2a9d25a7b229aed1dc75471e73a5 Mon Sep 17 00:00:00 2001 From: Rahix Date: Sun, 7 Feb 2021 13:28:05 +0100 Subject: [PATCH] Improve error message when no device is selected Introduce a new `device-selected` feature to simpilify the logic for showing an error when no device was selected. --- Cargo.toml | 33 +++++++++++++++++---------------- src/lib.rs | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e71b1c5..4818429 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,22 +21,23 @@ include = [ all-features = true [features] -atmega1280 = [] -atmega168 = [] -atmega2560 = [] -atmega8 = [] -atmega328p = [] -atmega328pb = [] -atmega4809 = [] -atmega48p = [] -atmega32u4 = [] -atmega64 = [] -atmega644 = [] -attiny84 = [] -attiny841 = [] -attiny85 = [] -attiny861 = [] -attiny88 = [] +device-selected = [] +atmega1280 = ["device-selected"] +atmega168 = ["device-selected"] +atmega2560 = ["device-selected"] +atmega8 = ["device-selected"] +atmega328p = ["device-selected"] +atmega328pb = ["device-selected"] +atmega4809 = ["device-selected"] +atmega48p = ["device-selected"] +atmega32u4 = ["device-selected"] +atmega64 = ["device-selected"] +atmega644 = ["device-selected"] +attiny84 = ["device-selected"] +attiny841 = ["device-selected"] +attiny85 = ["device-selected"] +attiny861 = ["device-selected"] +attiny88 = ["device-selected"] rt = ["avr-device-macros"] [dependencies] diff --git a/src/lib.rs b/src/lib.rs index 7c105b3..d236f4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,6 +80,31 @@ pub use avr_device_macros::interrupt; #[cfg(feature = "rt")] pub use avr_device_macros::entry; +#[cfg(not(feature = "device-selected"))] +compile_error!( + "This crate requires you to specify your target chip as a feature. + + Please select one of the following: + + * atmega1280 + * atmega168 + * atmega2560 + * atmega328p + * atmega328pb + * atmega32u4 + * atmega4809 + * atmega48p + * atmega64 + * atmega644 + * atmega8 + * attiny84 + * attiny841 + * attiny85 + * attiny861 + * attiny88 + " +); + #[allow(non_camel_case_types, unused_attributes, unreachable_patterns)] mod devices; @@ -115,23 +140,3 @@ pub use crate::devices::attiny85; pub use crate::devices::attiny861; #[cfg(feature = "attiny88")] pub use crate::devices::attiny88; - -#[cfg(not(any( - feature = "atmega1280", - feature = "atmega168", - feature = "atmega2560", - feature = "atmega8", - feature = "atmega328p", - feature = "atmega328pb", - feature = "atmega32u4", - feature = "atmega4809", - feature = "atmega48p", - feature = "atmega64", - feature = "atmega644", - feature = "attiny84", - feature = "attiny841", - feature = "attiny85", - feature = "attiny861", - feature = "attiny88", -)))] -compile_error!("You need to select at least one chip as a feature!"); -- 2.49.0