We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
It seems like this should work:
trait IntoBytes: Sized + Copy { fn into_bytes(&self, bytes: &mut [u8; size_of::<Self>()]) { let src = self as *const Self as *const u8; let dst: *mut u8 = &mut bytes[0]; unsafe { std::ptr::copy_nonoverlapping::<u8>(src, dst, bytes.len()); } } } impl IntoBytes for u64 {} impl IntoBytes for i64 {}
Or at least this:
trait IntoBytes<T: Sized>: Sized + Copy { fn into_bytes(&self, bytes: &mut [u8; size_of::<T>()]) { let src = self as *const Self as *const u8; let dst: *mut u8 = &mut bytes[0]; unsafe { std::ptr::copy_nonoverlapping::<u8>(src, dst, bytes.len()); } } } impl IntoBytes<u8> for u64 {} impl IntoBytes<u8> for i64 {}
The text was updated successfully, but these errors were encountered:
This seems to be related to #43408, but I also raise the possibility of Self.
Sorry, something went wrong.
Self in traits is essentially a generic parameter so this is really the same issue.
Self
Closing as a duplicate.
No branches or pull requests
It seems like this should work:
Or at least this:
The text was updated successfully, but these errors were encountered: