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

Make ConnectionManager implement Sync automatically #2321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mikeyhew
Copy link

@mikeyhew mikeyhew commented Mar 6, 2020

By using PhantomData<fn() -> T> instead of PhantomData<T> for the type of the _marker field, this makes ConnectionManager implement Sync automatically, and means we can remove the unsafe impl of Sync for ConnectionManager<T>.

By using `PhantomData<fn() -> T>` instead of `PhantomData<T>` for the type of the `_marker` field, this makes `ConnectionManager` implement `Sync` automatically, and means we can remove the `unsafe impl` of `Sync` for `ConnectionManager<T>`.
@weiznich weiznich requested a review from a team March 6, 2020 21:19
@@ -31,11 +31,9 @@ use crate::sql_types::HasSqlType;
#[derive(Debug, Clone)]
pub struct ConnectionManager<T> {
database_url: String,
_marker: PhantomData<T>,
_marker: PhantomData<fn() -> T>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, you should leave comment from PR description that explains, why not just PhantomData<T> is used

Copy link
Member

@weiznich weiznich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain why how change is equivalent (or at least equivalent sound) to the original code. Without this change T: 'static is enforced for the Sync bound. This bound is remove by changing the PhantomData type. See this playground for a toy example.

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.

None yet

3 participants