- `NextIf` iterator trait that yields the next element iff some predicate holds - `u64_from_u32s`, `u32s_from_u64`, `u32_from_u16s`, `u16s_from_u32` functions - moved `can_transmute` to `mem` module, added `is_same_size` and `is_aligned` functions - `copy_from` function for `TaggedAtomicPtr` - attempt at a sync queue? - `is_whitespace` function
23 lines
830 B
Rust
23 lines
830 B
Rust
pub const fn can_transmute<A, B>() -> bool {
|
|
use core::mem::{align_of, size_of};
|
|
// We can transmute `A` to `B` iff `A` and `B` have the same size and the
|
|
// alignment of `A` is greater than or equal to the alignment of `B`.
|
|
(size_of::<A>() == size_of::<B>()) & (align_of::<A>() >= align_of::<B>())
|
|
}
|
|
|
|
pub const fn is_same_size<A, B>() -> bool {
|
|
use core::mem::size_of;
|
|
|
|
size_of::<A>() == size_of::<B>()
|
|
}
|
|
|
|
/// Checks if `A` is aligned at least as well as `B`. e.g. `assert_aligned<u64,
|
|
/// u32>()` returns `true`, but `assert_aligned<u32, u64>()` returns
|
|
/// `false`. This is useful for ensuring that a type `A` can be safely cast to a
|
|
/// type `B` without violating alignment requirements.
|
|
pub const fn is_aligned<A, B>() -> bool {
|
|
use core::mem::align_of;
|
|
|
|
align_of::<A>() >= align_of::<B>()
|
|
}
|