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

add raw_field macro to compute raw ptr to field #40

Merged
merged 3 commits into from
Mar 16, 2020

Conversation

RalfJung
Copy link
Collaborator

Expose the part of offset_of! that computes a raw pointer to a field as a separate macro.
@Diggsey expressed that this would be interesting for their crate.

If rust-field-offset could depend on memoffset to use this macro, that would mean there is just one place we have to change once &raw (or an equivalent mechanism) becomes stable, so that everyone uses the blessed way to do this.

@Diggsey does this macro fit the needs of your crate?
@Gilnaa are you okay with adding this to the API surface of memoffset?

@Gilnaa
Copy link
Owner

Gilnaa commented Mar 16, 2020

Sure. Has anything changed since this in Feb7?

@RalfJung
Copy link
Collaborator Author

That was about using offset_of!, which is not possible with the existing API of rust-field-offset.

This PR is implementing the proposal a bit up that thread:

If there was a crate which implemented this macro: raw_address_of!((*ptr_to_undef).bar) and which guaranteed in the future to compile down to the MIR operator your RFC introduced, whilst for the moment making a "best effort" attempt, then I would be happy to use that to implement (2) in this crate.

@RalfJung RalfJung closed this Mar 16, 2020
@RalfJung RalfJung reopened this Mar 16, 2020
@Gilnaa Gilnaa merged commit 73f5ddd into Gilnaa:master Mar 16, 2020
@RalfJung
Copy link
Collaborator Author

Before making a release, let's see if the API works for @Diggsey

@RalfJung RalfJung deleted the raw_field branch March 16, 2020 17:05
@Gilnaa
Copy link
Owner

Gilnaa commented Mar 16, 2020

Sure

@Diggsey
Copy link

Diggsey commented Mar 16, 2020

Yeah, I'd be happy to depend on this crate for the raw_field function.

@Amanieu
Copy link
Contributor

Amanieu commented Mar 16, 2020

@RalfJung Does this macro resolve your concern here? #21 (comment)

@RalfJung
Copy link
Collaborator Author

@Amanieu this macro has nothing to do with container_of!. It just exposes something that we already did as part of offset_of! before, so there is no change to what happens to provenance.

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

Successfully merging this pull request may close these issues.

4 participants