Skip to content

Commit 3e60879

Browse files
authored
cpubits: bind a CPUBITS constant (#1423)
Uses the macro to bind a `u32` constant value representing the number of bits detected by the macro.
1 parent 2c3df3e commit 3e60879

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

cpubits/src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,18 @@ macro_rules! cfg_if {
278278
};
279279
}
280280

281+
/// Constant representing the detection result from `cpubits!` on the current target.
282+
pub const CPUBITS: u32 = {
283+
cpubits! {
284+
16 => { 16 }
285+
32 => { 32 }
286+
64 => { 64 }
287+
}
288+
};
289+
281290
#[cfg(test)]
282291
mod tests {
283-
/// Return an integer that maps to the number of bits `cpubits` detected.
284-
fn detected_bits() -> u32 {
285-
cpubits! {
286-
16 => { 16 }
287-
32 => { 32 }
288-
64 => { 64 }
289-
}
290-
}
292+
use super::CPUBITS;
291293

292294
/// Return an integer that maps to `target_pointer_width`.
293295
#[allow(dead_code)]
@@ -320,21 +322,21 @@ mod tests {
320322

321323
#[test]
322324
fn cpubits_works() {
323-
assert_eq!(detected_bits(), expected_bits());
325+
assert_eq!(CPUBITS, expected_bits());
324326
}
325327

326328
/// Explicit test for ARMv7 so we can see the predicate is working
327329
#[cfg(all(target_arch = "arm", not(target_feature = "thumb-mode")))]
328330
#[test]
329331
fn cpubits_on_armv7_is_64bit() {
330-
assert_eq!(detected_bits(), 64);
332+
assert_eq!(CPUBITS, 64);
331333
}
332334

333335
/// Explicit test for WASM so we can see the predicate is working
334336
#[cfg(target_arch = "wasm32")]
335337
#[test]
336338
fn cpubits_on_wasm_is_64bit() {
337-
assert_eq!(detected_bits(), 64);
339+
assert_eq!(CPUBITS, 64);
338340
}
339341

340342
#[test]

0 commit comments

Comments
 (0)