Fixed smaller units

pull/17/head
Erin 2023-10-29 20:38:57 +01:00
parent 0f619887c6
commit 1318e07a7b
2 changed files with 10 additions and 2 deletions

View File

@ -45,6 +45,8 @@ impl Value {
/// # Safety
/// - N/A, not to be implemented manually
pub unsafe trait ValueVariant: private::Sealed + Copy + Into<Value> {}
impl private::Sealed for Value {}
unsafe impl ValueVariant for Value {}
mod private {
pub trait Sealed {}

View File

@ -543,9 +543,15 @@ where
/// Write a register.
/// Writing to register 0 is no-op.
#[inline(always)]
fn write_reg(&mut self, n: u8, value: impl Into<Value>) {
fn write_reg<T: ValueVariant>(&mut self, n: u8, value: T) {
if n != 0 {
unsafe { *self.registers.get_unchecked_mut(n as usize) = value.into() };
unsafe {
core::ptr::copy_nonoverlapping(
(&value as *const T).cast::<u8>(),
self.registers.as_mut_ptr().add(n.into()).cast::<u8>(),
core::mem::size_of::<T>(),
);
};
}
}