Skip to content

Commit ae0d7f8

Browse files
committed
Validate runtime capacity against const generic in SPMC Ring configuration
1 parent 36c9690 commit ae0d7f8

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

aimdb-embassy-adapter/src/buffer.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
//! - `PubSubChannel<M, T, CAP, SUBS, PUBS>` - fixed capacity and subscriber/publisher counts
3030
//! - `Watch<M, T, N>` - fixed number of receivers
3131
//!
32-
//! The buffer configuration's runtime capacity parameter is validated but the actual capacity
33-
//! is determined by the const generic `CAP`. This is a design constraint of Embassy's no_std
32+
//! The buffer configuration's runtime capacity parameter must match the const generic `CAP`.
33+
//! A panic will occur if there's a mismatch. This is a design constraint of Embassy's no_std
3434
//! implementation.
3535
3636
use aimdb_core::buffer::{BufferBackend, BufferCfg, BufferReader};
@@ -124,9 +124,15 @@ impl<
124124

125125
fn new(cfg: &BufferCfg) -> Self {
126126
match cfg {
127-
BufferCfg::SpmcRing { capacity: _ } => {
127+
BufferCfg::SpmcRing { capacity } => {
128128
// Note: Embassy requires compile-time capacity, so we use CAP const generic
129-
// The runtime capacity parameter is validated but not used
129+
// Validate that the runtime capacity matches the const generic
130+
if *capacity != CAP {
131+
panic!(
132+
"BufferCfg::SpmcRing capacity ({}) does not match const generic CAP ({})",
133+
capacity, CAP
134+
);
135+
}
130136
Self::new_spmc()
131137
}
132138
BufferCfg::SingleLatest => Self::new_watch(),

0 commit comments

Comments
 (0)