Skip to content

Commit

Permalink
Added ::core prefix to assertions in const blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostie314159 committed Mar 1, 2025
1 parent 3013b0f commit 12c761c
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 137 deletions.
233 changes: 111 additions & 122 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ieee80211"
version = "0.5.3"
version = "0.5.4"
edition = "2021"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions src/common/aid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ macro_rules! aid {
use ::ieee80211::common::AssociationID;
// We could use inline const, but that would mean an MSRV of 1.79.0, which may be too recent.
const AID: AssociationID = {
assert!($aid != 0, "An AssociationID of zero is invalid.");
assert!($aid <= AssociationID::MAX_AID, "An AssociationID greater than 2007 is invalid");
::core::assert!($aid != 0, "An AssociationID of zero is invalid.");
::core::assert!($aid <= AssociationID::MAX_AID, "An AssociationID greater than 2007 is invalid");
AssociationID::new_unchecked($aid)
};
AID
Expand Down
10 changes: 5 additions & 5 deletions src/elements/ht/mcs_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ macro_rules! supported_rx_mcs_set {
$(
{
use ::ieee80211::macro_bits::{bit, check_bit, set_bit};
assert!($supported_rx_mcs_index >= 0, "MCS indices lower zero are invalid.");
assert!($supported_rx_mcs_index < 77, "MCS indices greater than 76 are invalid.");
::core::assert!($supported_rx_mcs_index >= 0, "MCS indices lower zero are invalid.");
::core::assert!($supported_rx_mcs_index < 77, "MCS indices greater than 76 are invalid.");

let (byte, bit) = ($supported_rx_mcs_index >> 3, $supported_rx_mcs_index & 0b0000_0111);
assert!(!check_bit!(buf[byte], bit!(bit)), concat!("MCS index: ", concat!($supported_rx_mcs_index, " is a duplicate.")));
::core::assert!(!check_bit!(buf[byte], bit!(bit)), concat!("MCS index: ", concat!($supported_rx_mcs_index, " is a duplicate.")));
set_bit!(buf[byte], bit!(bit));
}
)*
Expand All @@ -164,8 +164,8 @@ macro_rules! supported_rx_mcs_set {
{
const RESULT: [u8; 10] = {
use ::ieee80211::macro_bits::{bit, check_bit, set_bit};
assert!($start >= 0, "MCS indices lower zero are invalid.");
assert!($end < 77, "MCS indices greater than 76 are invalid.");
::core::assert!($start >= 0, "MCS indices lower zero are invalid.");
::core::assert!($end < 77, "MCS indices greater than 76 are invalid.");

let mut buf = [0x00; 10];

Expand Down
2 changes: 1 addition & 1 deletion src/elements/rates/extended_supported_rates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ macro_rules! extended_supported_rates {
),*
];
const _: () = {
assert!(RATES.len() <= 251, "More than 251 rates are invalid.");
::core::assert!(RATES.len() <= 251, "More than 251 rates are invalid.");
};
const RESULT: ExtendedSupportedRatesElement<[EncodedRate; RATE_COUNT]> = ExtendedSupportedRatesElement::new_unchecked(RATES);
RESULT
Expand Down
2 changes: 1 addition & 1 deletion src/elements/rates/supported_rates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ macro_rules! supported_rates {
),*
];
const _: () = {
assert!(RATES.len() <= 8, "More than eight rates are invalid.");
::core::assert!(RATES.len() <= 8, "More than eight rates are invalid.");
};
const RESULT: SupportedRatesElement<[EncodedRate; RATE_COUNT]> = SupportedRatesElement::new_unchecked(RATES);
RESULT
Expand Down
2 changes: 1 addition & 1 deletion src/elements/ssid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ macro_rules! ssid {
($ssid:expr) => {{
use ::ieee80211::elements::SSIDElement;
const RESULT: SSIDElement<'static> = {
assert!(
::core::assert!(
$ssid.as_bytes().len() <= 32,
"SSIDs must not exceed a length of more than 32 bytes."
);
Expand Down
4 changes: 2 additions & 2 deletions src/elements/tim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ macro_rules! tim_bitmap {
let mut n2 = 0;

$(
assert!($aid <= AssociationID::MAX_AID, "An AID higher than 2007 is invalid.");
::core::assert!($aid <= AssociationID::MAX_AID, "An AID higher than 2007 is invalid.");
// We actually set bit zero, if that AID is present, but it doesn't count towards N1.
let byte_index = ($aid / 8) as usize;
let bit_index = ($aid % 8) as usize;
Expand Down Expand Up @@ -464,7 +464,7 @@ macro_rules! tim_bitmap {
use ::ieee80211::{macro_bits::{set_bit, bit}, elements::tim::{TIMBitmapControl, TIMBitmap, ConstBitmap}, common::AssociationID};
const TRAFFIC_INDICATOR: bool = $min_aid == 0;
const PARTIAL_VIRTUAL_BITMAP: [u8; 251] = {
assert!($max_aid <= AssociationID::MAX_AID, "An AID higher than 2007 is invalid.");
::core::assert!($max_aid <= AssociationID::MAX_AID, "An AID higher than 2007 is invalid.");
let mut partial_virtual_bitmap = [0u8; 251];

let mut i = $min_aid;
Expand Down
2 changes: 1 addition & 1 deletion src/frames/data_frame/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! 1. Create a [DataFrameBuilder] with [new](DataFrameBuilder::new)
//! 2. Specify `ToDS` and `FromDS`, using [neither_to_nor_from_ds](DataFrameBuilder::neither_to_nor_from_ds), [to_ds](DataFrameBuilder::to_ds), [from_ds](DataFrameBuilder::from_ds) or [to_and_from_ds](DataFrameBuilder::to_and_from_ds).
//! 3. Specify a category, using [category_data](DataFrameBuilder::category_data), [category_data_null](DataFrameBuilder::category_data_null), [category_qos](DataFrameBuilder::category_qos) or [category_qos_null](DataFrameBuilder::category_qos_null). These are equivalent to [DataFrameCF], just as type state.
//! 3.5. If your selected category is not [DataNull] or [QoSNull], specify a payload using [payload](DataFrameBuilder::payload) or [payload_amsdu](DataFrameBuilder::payload_amsdu).
//! 3.5. If your selected category is not [DataNull] or [QoSNull], specify a payload using [payload](DataFrameBuilder::payload) or [payload_amsdu](DataFrameBuilder::payload_amsdu).
//! 4. Specify your addresses using [destination_address](DataFrameBuilder::destination_address), [source_address](DataFrameBuilder::source_address) and [bssid](DataFrameBuilder::bssid).
//! 5. Call [build](DataFrameBuilder::build).
//! ## Example
Expand Down
2 changes: 1 addition & 1 deletion tests/elements/ssid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn test_ssid_element_misc() {
);
// Not so fun fact: This test technically already caught an error, since I screwed up when writing the original function...
assert_eq!(
EXPECTED_SSID_STRING.as_bytes().len(),
EXPECTED_SSID_STRING.len(),
EXPECTED_SSID_ELEMENT.length_in_bytes(),
"Length in bytes returned didn't match what was expected."
);
Expand Down

0 comments on commit 12c761c

Please sign in to comment.