Skip to content

impl Data for a bunch of std types.#1534

Merged
richard-uk1 merged 3 commits intolinebender:masterfrom
richard-uk1:impl_data_for_std
Jan 14, 2021
Merged

impl Data for a bunch of std types.#1534
richard-uk1 merged 3 commits intolinebender:masterfrom
richard-uk1:impl_data_for_std

Conversation

@richard-uk1
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!

@richard-uk1 richard-uk1 merged commit 0008990 into linebender:master Jan 14, 2021
@richard-uk1
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.

@richard-uk1 richard-uk1 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