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

Consider using a *mut () to remove Send and Sync #7

Open
agashlin opened this issue May 6, 2019 · 0 comments
Open

Consider using a *mut () to remove Send and Sync #7

agashlin opened this issue May 6, 2019 · 0 comments

Comments

@agashlin
Copy link
Owner

agashlin commented May 6, 2019

In a few places I've seen a *mut () used to make a struct without Send and Sync traits, for instance this:

// We store a raw pointer because it's the only way at the moment to remove `Send`/`Sync` from the
// object.
struct ComInitialized(*mut ());

Currently I'm using PhantomData<Rc<()>> for the same:

comedy-rs/src/com.rs

Lines 142 to 148 in c244b91

pub struct ComApartmentScope {
/// PhantomData used in lieu of unstable impl !Send + !Sync.
/// It must be dropped on the same thread it was created on so it can't be Send,
/// and references are meant to indicate that COM has been inited on the current thread so it
/// can't be Sync.
_do_not_send: PhantomData<Rc<()>>,
}

I think PhantomData is still the right way to go, but it may be clearer to do PhantomData<*mut ()>. I don't know if there is any practical difference.

Also using a tuple struct instead of one unused named field would be less noisy.

While I'm at it, there should be a compile_fail doctest to ensure Send and Sync are missing (I don't know of any other way to assert a negative impl).

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