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

impl Data for a bunch of std types. #1534

Merged
merged 3 commits into from
Jan 14, 2021

Conversation

derekdreery
Copy link
Collaborator

This patch implements Data for some more types in std. My motivation was SystemTime, but I thought I may as well implement it anywhere else it made sense.

Copy link
Collaborator

@maan2003 maan2003 left a comment

Choose a reason for hiding this comment

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

Looks good to me. But I am not sure about the raw pointers.

Comment on lines 297 to 309
impl<T: 'static + ?Sized> Data for *const T {
fn same(&self, other: &Self) -> bool {
// This Does not dereference the pointer, only the reference to the pointer.
ptr::eq(*self, *other)
}
}

impl<T: 'static + ?Sized> Data for *mut T {
fn same(&self, other: &Self) -> bool {
// This Does not dereference the pointer, only the reference to the pointer.
ptr::eq(*self, *other)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would leave these ones. When someone has raw pointers, they are better using same_fn. But if you add these, then also add NonNull

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm OK I'm sold on removing the raw pointers.

Copy link
Member

Choose a reason for hiding this comment

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

yes I agree I struggle to think of a good case where you'd want this.

The user should handle this themselves safely.
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

This makes sense, thanks!

@derekdreery derekdreery merged commit 0008990 into linebender:master Jan 14, 2021
@derekdreery
Copy link
Collaborator Author

I had a look at implementing it for Pin, but the types were complex, and I'm not sure exactly what it means to ptr-compare pinned things. Can always be added later anyway.

@derekdreery derekdreery deleted the impl_data_for_std branch January 14, 2021 16:55
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.

3 participants