Skip to content

Conversation

nspin
Copy link
Owner

@nspin nspin commented Jan 27, 2024

Parameterize VolatileRef and VolatilePtr over O: Ops.

#[repr(transparent)]
pub struct VolatileRef<'a, T, A = ReadWrite, O = VolatileOps>
where
    T: ?Sized,
{
    // ...
}

#[repr(transparent)]
pub struct VolatilePtr<'a, T, A = ReadWrite, O = VolatileOps>
where
    T: ?Sized,
{
    // ...
}

pub trait Ops: Copy + Default {}

pub trait UnitaryOps<T>: Ops {
    unsafe fn read(src: *const T) -> T;
    unsafe fn write(dst: *mut T, src: T);
}

pub trait BulkOps<T>: Ops {
    unsafe fn memmove(dst: *mut T, src: *const T, count: usize);
    unsafe fn memcpy(dst: *mut T, src: *const T, count: usize);
    unsafe fn memset(dst: *mut T, val: u8, count: usize);
}

#[derive(Default, Copy, Clone)]
pub struct VolatileOps;

impl Ops for VolatileOps {}

impl<T> UnitaryOps<T> for VolatileOps {
    // ...
}

#[cfg(feature = "unstable")]
impl<T> BulkOps<T> for VolatileOps {
    // ...
}

@nspin nspin marked this pull request as draft January 27, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant