Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ByteValued for i128/u128 #238

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Added

- [[#237]](https://github.com/rust-vmm/vm-memory/pull/237) Implement `ByteValued` for `i/u128`.

## [v0.11.0]

### Added
Expand Down
8 changes: 6 additions & 2 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ byte_valued_type!(u8);
byte_valued_type!(u16);
byte_valued_type!(u32);
byte_valued_type!(u64);
byte_valued_type!(u128);
byte_valued_type!(usize);
byte_valued_type!(i8);
byte_valued_type!(i16);
byte_valued_type!(i32);
byte_valued_type!(i64);
byte_valued_type!(i128);
byte_valued_type!(isize);

/// A trait used to identify types which can be accessed atomically by proxy.
Expand Down Expand Up @@ -362,7 +364,7 @@ pub(crate) mod tests {
where
T: ByteValued + PartialEq + Debug + Default,
{
let mut data = [0u8; 32];
let mut data = [0u8; 48];
let pre_len = {
let (pre, _, _) = unsafe { data.align_to::<T>() };
pre.len()
Expand All @@ -377,7 +379,7 @@ pub(crate) mod tests {
assert_eq!(val.as_mut_slice(), aligned_data);
}
}
for i in 1..size_of::<T>() {
for i in 1..size_of::<T>().min(align_of::<T>()) {
let begin = pre_len + i;
let end = begin + size_of::<T>();
let unaligned_data = &mut data[begin..end];
Expand All @@ -401,11 +403,13 @@ pub(crate) mod tests {
check_byte_valued_type::<u16>();
check_byte_valued_type::<u32>();
check_byte_valued_type::<u64>();
check_byte_valued_type::<u128>();
check_byte_valued_type::<usize>();
check_byte_valued_type::<i8>();
check_byte_valued_type::<i16>();
check_byte_valued_type::<i32>();
check_byte_valued_type::<i64>();
check_byte_valued_type::<i128>();
check_byte_valued_type::<isize>();
}

Expand Down