-
Notifications
You must be signed in to change notification settings - Fork 51
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
Procedural Macro for implementing SharedMemCast #25
Conversation
…ny of the fields just yet
Thanks a lot for your work and the good documentation 👍 I should have time in the next few days to take a quick glance and merge it into master |
Thank you! Appreciate you taking the time to look at it. :) |
@elast0ny I realized that we were missing some impls for a few primitive types, After some thought, I think it might also be okay to add impls of Here's the updated documentation screenshot for the impls I added: |
Please pretty please can we have this? I got hit by there being no |
This PR was merged into a bigger PR #30 Thanks again for your work and sorry for the delays ! |
Fixes #17.
Hello! Thanks for the great crate. I want to use this for a project and I noticed that you needed a custom derive for the
SharedMemCast
trait. This is really useful for using this crate without having to write the unsafe impl, so I thought I would help out and contribute the macro. :)The size of this PR is probably quite daunting, so I'll give you an overview of what I had to do so you understand each step:
shared_memory
is compiled. I called this crateshared_memory_derive
and added it to the root directory of the project.SharedMemCast
proc macro fromsrc/lib.rs
and make using the macro convenient, I needed to upgrade the crate to the 2018 edition. I didn't want my changes to be too obtrusive, so I only added theedition = 2018
line in theCargo.toml
file and made the most minimal changes to fix any errors that cropped up. You can always usecargo fix
to finish the upgrade later if you feel the need to do that.Cargo.toml
file into theshared_memory_derive/Cargo.toml
file. I made sure that the versions of both crates are in sync. This can be useful to avoid confusion. Please make sure you publishshared_memory_derive
before publishingshared_memory
to avoid any problems.trybuild
crate for that. The tests intests/ui
are all meant to produce compiler errors and the tests intests/run-pass
are all meant to compile with no errors. See theCONTRIBUTING.md
file I added for more details.PhantomData<T>
,()
,[T; 0]
, unit structs, etc.) I've disabled them (by producing a compiler error) because it made the most sense to me that they should not ever be casted from shared memory. The same goes for empty enums which should never be initialized.SharedMemCast
trait to be implemented for various sizes of fixed-size array. Rust has no type-level integer support just yet, so the solution that every crate uses is to have a bunch of impls for different sizes. I think we can cover a large number of use-cases by having impls for all sizes between 1 and 32, then the powers of 2 up to about 2 GB. Seecast.rs
for what I mean by that. I think these impls should be more than enough for most peoples' needs and we can always add more later.examples/
directory to use#[derive]
instead ofunsafe impl
. I also updated the docs to let people know that this feature exists. See below for a screenshot of that.--all
flag. This should ensure that the custom derive tests also run on CI.These steps can be roughly seen in my commits as well if you prefer to go through things that way. Please don't hesitate to ask me any questions about all of this and do let me know if I've missed describing any part of what I did.
Thanks again for the great library! Looking forward to using it once these changes land and everything is published. 😄
Documentation Screenshot
Only the docs for
SharedMemCast
were updated: