[−][src]Macro syllogism::define_compatibility
A macro to define traits and other macros that help to implement IsNot
and Specialize
across crates.
The macro expects the dollar symbol (for technical reasons), followed by a comma-separated list of (trait, macro) pairs. The macro expands to definitions of these traits and macros. Each trait and macro may be preceded by a meta attribute (e.g. a doc comment in the form of #[doc="..."]).
Note
The trailing comma after the last pair is mandatory.
Notes on meta attributes
Meta attributes are only inserted at the declaration of the traits and the macros, so
#[cfg(...)]
attributes do not work.
Meta attributes may be doc comments starting with ///
, as illustrated in the example below.
Example
define_compatibility!( $ ( /// Lorem ipsum NotInCrate1, #[doc(hidden)] macro_for_crate1 ), (NotInCrate2, macro_for_crate2), (NotInCrate3, macro_for_crate3), );
This expands to the following:
/// Lorem ipsum trait NotInCrate1 {} trait NotInCrate2 {} trait NotInCrate3 {} #[doc(hidden)] macro_rules! macro_for_crate1 { // See below for more information. } macro_rules! macro_for_crate2 { // See below for more information. } macro_rules! macro_for_crate3 { // See below for more information. }
The generated macros can in turn be used in the following way:
struct MyStruct { // ... } struct MyGenericStruct<T> { // ... } macro_for_crate1!(impl trait for MyStruct {}); macro_for_crate1!(impl<T> trait for MyGenericStruct<T> {});
This expands to the following:
impl NotInCrate2 for MyStruct {} impl NotInCrate3 for MyStruct {} impl<T> NotInCrate2 for MyGenericStruct<T> {} impl<T> NotInCrate3 for MyGenericStruct<T> {}