Skip to content

Commit a60d388

Browse files
committed
Make sure different packetmeta-id reqs don't interfere
1 parent bb4b13d commit a60d388

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

smoltcp-device/src/lib.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,20 +340,44 @@ pub trait TxToken {
340340
///
341341
/// This struct is marked as `#[non_exhaustive]`. This means it is not possible to
342342
/// create it directly by specifying all fields. You have to instead create it with
343-
/// default values and then set the fields you want. This makes adding metadata
344-
/// fields a non-breaking change.
343+
/// default values and then set the fields you want using setters. This makes adding
344+
/// metadata fields, as well as mixing multiple device implementations with different
345+
/// metadata fields, a non-breaking change.
345346
///
346347
/// ```rust
347348
/// let mut meta = smoltcp_devicephy::PacketMeta::default();
348349
/// #[cfg(feature = "packetmeta-id")]
349350
/// {
350-
/// meta.id = 15;
351+
/// meta.set_id(15);
351352
/// }
352353
/// ```
353354
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
354355
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Default)]
355356
#[non_exhaustive]
356357
pub struct PacketMeta {
357358
#[cfg(feature = "packetmeta-id")]
358-
pub id: u32,
359+
id: Option<u32>,
360+
}
361+
362+
impl PacketMeta {
363+
#[inline]
364+
pub fn set_id(&mut self, _id: u32) {
365+
#[cfg(feature = "packetmeta-id")]
366+
{
367+
self.id = Some(_id);
368+
}
369+
}
370+
371+
#[inline]
372+
pub fn id(&self) -> Option<u32> {
373+
#[cfg(feature = "packetmeta-id")]
374+
{
375+
self.id
376+
}
377+
378+
#[cfg(not(feature = "packetmeta-id"))]
379+
{
380+
None
381+
}
382+
}
359383
}

0 commit comments

Comments
 (0)