Align: add bytes_usize and bits_usize
This commit is contained in:
parent
20aa2d81e3
commit
65d74785d7
@ -742,11 +742,21 @@ pub fn bytes(self) -> u64 {
|
|||||||
1 << self.pow2
|
1 << self.pow2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn bytes_usize(self) -> usize {
|
||||||
|
self.bytes().try_into().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn bits(self) -> u64 {
|
pub fn bits(self) -> u64 {
|
||||||
self.bytes() * 8
|
self.bytes() * 8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn bits_usize(self) -> usize {
|
||||||
|
self.bits().try_into().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
/// Computes the best alignment possible for the given offset
|
/// Computes the best alignment possible for the given offset
|
||||||
/// (the largest power of two that the offset is a multiple of).
|
/// (the largest power of two that the offset is a multiple of).
|
||||||
///
|
///
|
||||||
|
@ -266,7 +266,7 @@ pub fn from_ty(
|
|||||||
|
|
||||||
ty::Ref(lifetime, ty, mutability) => {
|
ty::Ref(lifetime, ty, mutability) => {
|
||||||
let ty_and_layout = cx.layout_of(*ty)?;
|
let ty_and_layout = cx.layout_of(*ty)?;
|
||||||
let align = ty_and_layout.align.abi.bytes() as usize;
|
let align = ty_and_layout.align.abi.bytes_usize();
|
||||||
let size = ty_and_layout.size.bytes_usize();
|
let size = ty_and_layout.size.bytes_usize();
|
||||||
Ok(Tree::Ref(Ref {
|
Ok(Tree::Ref(Ref {
|
||||||
lifetime: *lifetime,
|
lifetime: *lifetime,
|
||||||
|
Loading…
Reference in New Issue
Block a user