Use #[non_exhaustive] to make individual structs non-constructible
diff --git a/src/adc.rs b/src/adc.rs
index 7914a6a..7a18cce 100644
--- a/src/adc.rs
+++ b/src/adc.rs
@@ -24,9 +24,8 @@
pub const BUFFER_ALT: usize = 1;
}
-pub struct AdcDriver {
- pub(crate) _unconstructible: (),
-}
+#[non_exhaustive]
+pub struct AdcDriver;
impl AdcDriver {
pub fn with_callback<CB>(self, callback: CB) -> WithCallback<CB> {
diff --git a/src/buttons.rs b/src/buttons.rs
index 850dd11..7004cd8 100644
--- a/src/buttons.rs
+++ b/src/buttons.rs
@@ -17,9 +17,8 @@
pub const SUBSCRIBE_CALLBACK: usize = 0;
}
-pub struct ButtonDriver {
- pub(crate) _unconstructible: (),
-}
+#[non_exhaustive]
+pub struct ButtonDriver;
impl ButtonDriver {
pub fn with_callback<CB>(self, callback: CB) -> WithCallback<CB> {
diff --git a/src/console.rs b/src/console.rs
index fb65af7..87ab382 100644
--- a/src/console.rs
+++ b/src/console.rs
@@ -20,9 +20,8 @@
pub const SHARE_BUFFER: usize = 1;
}
-pub struct ConsoleDriver {
- pub(crate) _unconstructible: (),
-}
+#[non_exhaustive]
+pub struct ConsoleDriver;
impl ConsoleDriver {
pub fn create_console(self) -> Console {
diff --git a/src/drivers.rs b/src/drivers.rs
index 5f635eb..567f67b 100644
--- a/src/drivers.rs
+++ b/src/drivers.rs
@@ -56,48 +56,22 @@
#[allow(clippy::declare_interior_mutable_const)]
const DRIVERS: Drivers = Drivers {
- console_driver: ConsoleDriver {
- _unconstructible: (),
- },
- led_driver: LedDriver {
- _unconstructible: (),
- },
+ adc_driver: AdcDriver,
+ ble_advertising_driver: BleAdvertisingDriver,
+ ble_scanning_driver: BleScanningDriver,
+ button_driver: ButtonDriver,
+ console_driver: ConsoleDriver,
+ led_driver: LedDriver,
timer_context: DriverContext {
active_timer: Cell::new(None),
},
- gpio_driver: GpioDriver {
- _unconstructible: (),
- },
- temperature_driver: TemperatureDriver {
- _unconstructible: (),
- },
- button_driver: ButtonDriver {
- _unconstructible: (),
- },
- adc_driver: AdcDriver {
- _unconstructible: (),
- },
- rng_driver: RngDriver {
- _unconstructible: (),
- },
- ble_advertising_driver: BleAdvertisingDriver {
- _unconstructible: (),
- },
- ble_scanning_driver: BleScanningDriver {
- _unconstructible: (),
- },
- ambient_light_sensor: AmbientLightSensor {
- _unconstructible: (),
- },
- temperature_sensor: TemperatureSensor {
- _unconstructible: (),
- },
- humidity_sensor: HumiditySensor {
- _unconstructible: (),
- },
- ninedof_driver: NinedofDriver {
- _unconstructible: (),
- },
+ gpio_driver: GpioDriver,
+ temperature_driver: TemperatureDriver,
+ rng_driver: RngDriver,
+ ambient_light_sensor: AmbientLightSensor,
+ temperature_sensor: TemperatureSensor,
+ humidity_sensor: HumiditySensor,
+ ninedof_driver: NinedofDriver,
};
static mut DRIVERS_SINGLETON: Option<Drivers> = Some(DRIVERS);
diff --git a/src/gpio.rs b/src/gpio.rs
index c42b43d..6f87e44 100644
--- a/src/gpio.rs
+++ b/src/gpio.rs
@@ -22,9 +22,8 @@
pub const SUBSCRIBE_CALLBACK: usize = 0;
}
-pub struct GpioDriver {
- pub(crate) _unconstructible: (),
-}
+#[non_exhaustive]
+pub struct GpioDriver;
impl GpioDriver {
pub fn all_pins<'a>(&'a self) -> TockResult<GpioIter<'a>> {
diff --git a/src/led.rs b/src/led.rs
index b8c669a..26a4c82 100644
--- a/src/led.rs
+++ b/src/led.rs
@@ -11,9 +11,8 @@
pub const TOGGLE: usize = 3;
}
-pub struct LedDriver {
- pub(crate) _unconstructible: (),
-}
+#[non_exhaustive]
+pub struct LedDriver;
pub struct Led<'a> {
led_num: usize,
diff --git a/src/rng.rs b/src/rng.rs
index 1fb647c..e04500f 100644
--- a/src/rng.rs
+++ b/src/rng.rs
@@ -18,9 +18,8 @@
pub const SHARE_BUFFER: usize = 0;
}
-pub struct RngDriver {
- pub(crate) _unconstructible: (),
-}
+#[non_exhaustive]
+pub struct RngDriver;
impl RngDriver {
pub async fn fill_buffer(&mut self, buf: &mut [u8]) -> TockResult<()> {
diff --git a/src/sensors/mod.rs b/src/sensors/mod.rs
index e441f22..c4b962f 100644
--- a/src/sensors/mod.rs
+++ b/src/sensors/mod.rs
@@ -52,9 +52,8 @@
}
}
- pub struct $sensor_name {
- pub(crate) _unconstructible: (),
- }
+ #[non_exhaustive]
+ pub struct $sensor_name;
impl Sensor<$type_name> for $sensor_name {
fn driver_num(&self) -> usize {
diff --git a/src/sensors/ninedof.rs b/src/sensors/ninedof.rs
index e17da67..3e16f75 100644
--- a/src/sensors/ninedof.rs
+++ b/src/sensors/ninedof.rs
@@ -8,9 +8,8 @@
const DRIVER_NUM: usize = 0x60004;
-pub struct NinedofDriver {
- pub(crate) _unconstructible: (),
-}
+#[non_exhaustive]
+pub struct NinedofDriver;
#[derive(Copy, Clone, Default, Debug)]
pub struct NinedofReading {
@@ -61,9 +60,7 @@
impl Default for NinedofDriver {
fn default() -> Self {
- NinedofDriver {
- _unconstructible: (),
- }
+ NinedofDriver
}
}
diff --git a/src/simple_ble.rs b/src/simple_ble.rs
index ab108cd..f700385 100644
--- a/src/simple_ble.rs
+++ b/src/simple_ble.rs
@@ -35,9 +35,8 @@
pub const SERVICE_DATA: usize = 0x16;
}
-pub struct BleAdvertisingDriver {
- pub(crate) _unconstructible: (),
-}
+#[non_exhaustive]
+pub struct BleAdvertisingDriver;
impl BleAdvertisingDriver {
pub fn create_advertising_buffer() -> [u8; BUFFER_SIZE_ADVERTISE] {
@@ -86,9 +85,8 @@
}
}
-pub struct BleScanningDriver {
- pub(crate) _unconstructible: (),
-}
+#[non_exhaustive]
+pub struct BleScanningDriver;
impl BleScanningDriver {
pub fn create_scan_buffer() -> [u8; BUFFER_SIZE_SCAN] {
diff --git a/src/temperature.rs b/src/temperature.rs
index 995bce2..4420791 100644
--- a/src/temperature.rs
+++ b/src/temperature.rs
@@ -16,9 +16,8 @@
pub const SUBSCRIBE_CALLBACK: usize = 0;
}
-pub struct TemperatureDriver {
- pub(crate) _unconstructible: (),
-}
+#[non_exhaustive]
+pub struct TemperatureDriver;
impl TemperatureDriver {
pub async fn measure_temperature(&mut self) -> Result<Temperature, TockError> {
diff --git a/src/timer.rs b/src/timer.rs
index c1cf1a0..80adc1a 100644
--- a/src/timer.rs
+++ b/src/timer.rs
@@ -295,6 +295,7 @@
/// # Ok(())
/// # }
/// ```
+#[non_exhaustive]
pub struct DriverContext {
pub(crate) active_timer: Cell<Option<ActiveTimer>>,
}