Macro abi_stable::tag
source · macro_rules! tag { ([ $( $elem:expr ),* $(,)? ]) => { ... }; ({ $( $key:expr=>$value:expr ),* $(,)? }) => { ... }; ({ $( $key:expr ),* $(,)? }) => { ... }; ($expr:expr) => { ... }; }
Expand description
Constructs a Tag
,
a dynamically typed value for users to check extra properties about their types
when doing runtime type checking.
Note that this macro is not recursive, you need to invoke it every time you construct an array/map/set inside of the macro.
For more examples look in the tagging module
Example
Using tags to store the traits the type requires, so that if this changes it can be reported as an error.
This will cause an error if the binary and dynamic library disagree about the values inside the “required traits” map entry .
In real code this should be written in a way that keeps the tags and the type bounds in sync.
use abi_stable::{
tag,
type_layout::Tag,
StableAbi,
};
const TAGS: Tag = tag!{{
"required traits" => tag![["Copy"]],
}};
#[repr(C)]
#[derive(StableAbi)]
#[sabi(bound(T: Copy))]
#[sabi(tag = TAGS)]
struct Value<T>{
value: T,
}