Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully generic sysvar implementations #5

Open
tgross35 opened this issue Feb 8, 2023 · 0 comments
Open

Fully generic sysvar implementations #5

tgross35 opened this issue Feb 8, 2023 · 0 comments

Comments

@tgross35
Copy link

tgross35 commented Feb 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant