all: remove unnecessary mem:: prefix
This commit is contained in:
parent
c00ef63afe
commit
1e45a243de
22 changed files with 61 additions and 76 deletions
|
|
@ -101,7 +101,7 @@ impl<'a> MsgFormatter<'a> {
|
|||
}
|
||||
|
||||
pub fn binary<T: ?Sized + Packed>(&mut self, t: &T) -> &mut Self {
|
||||
self.uint(mem::size_of_val(t) as u32);
|
||||
self.uint(size_of_val(t) as u32);
|
||||
self.write(uapi::as_bytes(t));
|
||||
let none = [0; 4];
|
||||
self.write(&none[..self.meta.write_pos.wrapping_neg() & 3]);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use {
|
||||
crate::{fixed::Fixed, globals::GlobalName, object::ObjectId, utils::buffd::BufFdIn},
|
||||
bstr::{BStr, ByteSlice},
|
||||
std::{mem, ptr, rc::Rc},
|
||||
std::{ptr, rc::Rc},
|
||||
thiserror::Error,
|
||||
uapi::{OwnedFd, Pod},
|
||||
};
|
||||
|
|
@ -122,30 +122,30 @@ impl<'a, 'b> MsgParser<'a, 'b> {
|
|||
|
||||
pub fn binary<T: Pod>(&mut self) -> Result<T, MsgParserError> {
|
||||
let array = self.array()?;
|
||||
if array.len() < mem::size_of::<T>() {
|
||||
if array.len() < size_of::<T>() {
|
||||
return Err(MsgParserError::UnexpectedEof);
|
||||
}
|
||||
if array.len() > mem::size_of::<T>() {
|
||||
if array.len() > size_of::<T>() {
|
||||
return Err(MsgParserError::BinaryArrayTooLarge);
|
||||
}
|
||||
unsafe { Ok(ptr::read_unaligned(array.as_ptr() as _)) }
|
||||
}
|
||||
|
||||
pub fn binary_array<T: Pod>(&mut self) -> Result<&'b [T], MsgParserError> {
|
||||
if std::mem::align_of::<T>() > 4 {
|
||||
if align_of::<T>() > 4 {
|
||||
panic!("Alignment of binary array element is too large");
|
||||
};
|
||||
if std::mem::size_of::<T>() == 0 {
|
||||
if size_of::<T>() == 0 {
|
||||
panic!("Size of binary array element is 0");
|
||||
};
|
||||
let array = self.array()?;
|
||||
if array.len() % mem::size_of::<T>() != 0 {
|
||||
if array.len() % size_of::<T>() != 0 {
|
||||
return Err(MsgParserError::BinaryArraySize);
|
||||
}
|
||||
unsafe {
|
||||
Ok(std::slice::from_raw_parts(
|
||||
array.as_ptr() as _,
|
||||
array.len() / mem::size_of::<T>(),
|
||||
array.len() / size_of::<T>(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue