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

Cannot use derive macros when reexporting bytemuck from library #208

Open
AndriBaal opened this issue Sep 6, 2023 · 4 comments
Open

Cannot use derive macros when reexporting bytemuck from library #208

AndriBaal opened this issue Sep 6, 2023 · 4 comments

Comments

@AndriBaal
Copy link
Contributor

I have a crate that reexports bytemuck including its derive feature. I also have a derive macro that creates a new struct which should implement Pod and Zeroable. The problem I have is, that I cannot implement those traits on the struct using the safe derive macro because i get the following error:

error[E0433]: failed to resolve: could not find `bytemuck` in the list of imported crate

I assume this error occurs becuase the the crate uses ::bytemuck which always uses bytemuck as an extern crate dependency.

serde has a very elegant way to bypass this issue: serde-rs/serde#1465 (comment)

It would be nice to see something like this in the future, so that you can reexport bytemuck and still use the derive macros:

#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
#[bytemuck(crate = "self::bytemuck")]
#[repr(C)]
struct Test {
    position: InstancePosition,
    color: Color,
}

If the dev team would be interested in such a feature, I would be happy to make a pull request.

@Lokathor
Copy link
Owner

Lokathor commented Sep 6, 2023

this appears to be the same problem as #93

I'd be happy to see some sort of fix here, but I'm not 100% sure that the fix you're proposing is the correct one. At a glance it seems fine. If you make the PR I can certainly point people at it to do the review.

@AndriBaal
Copy link
Contributor Author

I have now implemented it in a similar way as serde #209

@cst0ny
Copy link

cst0ny commented Aug 29, 2024

This issue should be closed as far as i can tell.

I cant find where this has been documented (CHANGELOG, docs.rs, etc...) but you can now do this in bytemuck 1.17 :
https://github.com/Lokathor/bytemuck/blob/main/derive/tests/basic.rs#L457

#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable, bytemuck::ByteEq)]
#[bytemuck(crate = "reexport_name")]
#[repr(C)]
struct Issue93 {}

@Lokathor
Copy link
Owner

I'll keep it open as a reminder to put this in docs somewhere, then we can close it.

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

3 participants