I think I actually came up with a way to make sysvar implementations fully generic using struct update syntax. Proof:
struct St {
x: *mut i32,
y: i32
}
unsafe impl Sync for St {}
trait Foo {
const DEFAULT_ST: St = St{x: std::ptr::null_mut(), y: 0};
}
struct Bar;
impl Foo for Bar {}
static TEST: St = St {x: 0x123 as *mut i32, ..Bar::DEFAULT_ST};
The proc macro would create something like TEST. Just needs to detect string literals and convert them to c strings, and keep a map of field mappings.
To keep safety, 1. this trait needs to be marked unsafe and 2. our proc macro should check and reject raw pointer
I think I actually came up with a way to make sysvar implementations fully generic using struct update syntax. Proof:
The proc macro would create something like
TEST. Just needs to detect string literals and convert them to c strings, and keep a map of field mappings.To keep safety, 1. this trait needs to be marked unsafe and 2. our proc macro should check and reject raw pointer