Currently, the derive_xrb!
macro derives X11Size
, Readable
, and Writable
for all structs and enums. This should be changed so that one can opt into deriving these traits by matching the derive syntax - i.e. derive attributes are parsed, XRBK derives are stripped from the attributes, and the macro derives for the traits that were present in the derive attributes.
Perhaps better syntax highlighting for the other attributes could be done by instead leaving the derives on, but putting another attribute (perhaps reusing the #[hide]
attribute but on the whole item) so that the derive macros know not to actually derive as usual. I think this is the only way to do syntax highlighting (other option being a dummy derive macro), because the other way for us to define attributes is attribute macros, but they are active: they get removed from use anyway (and generate weird errors when I tried).
Examples
derive_xrb! {
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, X11Size, Writable, Readable)]
pub struct Point {
pub x: i32,
pub y: i32,
}
}
This example would be the same as if you weren't to use the derive_xrb!
macro.
derive_xrb! {
#[derive(Clone, Eq, PartialEq, Hash, Debug, X11Size, Readable, Writable)]
pub struct Host {
pub family: HostFamily,
_,
#[allow(clippy::cast_possible_truncation)]
let address_len: u16 = address => address.len() as u16,
#[context(address_len => *address_len as usize)]
pub address: Vec<u8>,
[_; ..],
}
}
This example uses the derive_xrb!
syntax, but enables deriving the XRBK traits only by including them in the #[derive(...)]
attribute.