Macro const_known_value

Source
macro_rules! const_known_value {
    ($value:expr, $const_name:ident, $name:expr) => { ... };
}
Expand description

A macro that declares a known value at compile time.

This macro creates two constants:

  • A raw u64 value constant with the suffix _RAW
  • A KnownValue constant with the given name and value

This is used internally to define all the standard Known Values in the registry.

ยงExamples

use known_values::*;
use paste::paste;

// Define a custom known value
const_known_value!(1000, MY_CUSTOM_VALUE, "myCustomValue");

// Now MY_CUSTOM_VALUE is a constant KnownValue
assert_eq!(MY_CUSTOM_VALUE.value(), 1000);
assert_eq!(MY_CUSTOM_VALUE.name(), "myCustomValue");

paste! {
    // MY_CUSTOM_VALUE_RAW is the raw u64 value
    assert_eq!([<MY_CUSTOM_VALUE _RAW>], 1000);
}