Rollup merge of #97034 - fee1-dead-contrib:layout-hash, r=dtolnay
Implement `Hash` for `core::alloc::Layout` This was brought up on [reddit](https://www.reddit.com/r/rust/comments/uoypui/the_standard_library_types_are_good_except_when/), and I don't see why Layout shouldn't implement `Hash`. Feel free to comment if I am wrong though :)
This commit is contained in:
commit
880d3ea3c2
2 changed files with 9 additions and 2 deletions
|
@ -26,7 +26,7 @@ const fn size_align<T>() -> (usize, usize) {
|
||||||
/// like this are met, use specific allocators with looser
|
/// like this are met, use specific allocators with looser
|
||||||
/// requirements, or use the more lenient `Allocator` interface.)
|
/// requirements, or use the more lenient `Allocator` interface.)
|
||||||
#[stable(feature = "alloc_layout", since = "1.28.0")]
|
#[stable(feature = "alloc_layout", since = "1.28.0")]
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
#[lang = "alloc_layout"]
|
#[lang = "alloc_layout"]
|
||||||
pub struct Layout {
|
pub struct Layout {
|
||||||
// size of the requested block of memory, measured in bytes.
|
// size of the requested block of memory, measured in bytes.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::convert::TryFrom;
|
use crate::convert::TryFrom;
|
||||||
use crate::num::NonZeroUsize;
|
use crate::num::NonZeroUsize;
|
||||||
use crate::{cmp, fmt, mem, num};
|
use crate::{cmp, fmt, hash, mem, num};
|
||||||
|
|
||||||
/// A type storing a `usize` which is a power of two, and thus
|
/// A type storing a `usize` which is a power of two, and thus
|
||||||
/// represents a possible alignment in the rust abstract machine.
|
/// represents a possible alignment in the rust abstract machine.
|
||||||
|
@ -105,6 +105,13 @@ impl cmp::PartialOrd for ValidAlign {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl hash::Hash for ValidAlign {
|
||||||
|
#[inline]
|
||||||
|
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||||
|
self.as_nonzero().hash(state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "16")]
|
#[cfg(target_pointer_width = "16")]
|
||||||
type ValidAlignEnum = ValidAlignEnum16;
|
type ValidAlignEnum = ValidAlignEnum16;
|
||||||
#[cfg(target_pointer_width = "32")]
|
#[cfg(target_pointer_width = "32")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue