Skip to content

Best of both worlds API? #15

Closed
Closed
@coolreader18

Description

@coolreader18

I think there's a way to combine the APIs of 0.3 and 0.4, to be able to have both easy volatile references as well as a substitute for C's volatile typ var; variable declarations (which I was primarily using volatile 0.3 for). I'm imagining something similar to this:

pub struct VolatileRef<R, A> {
    reference: R,
    access: PhantomData<A>,
}
// same as current Volatile functions, except for below name changes
impl<R> VolatileRef<R, ReadWrite> {
    // or maybe from_ref?
    pub const fn new_ref(reference: R) -> Self;
}
impl<R> VolatileRef<R, ReadOnly> {
    pub const fn new_ref_read_only(reference: R) -> Self;
}
impl<R> VolatileRef<R, WriteOnly> {
    pub const fn new_ref_write_only(reference: R) -> Self;
}

// not sure about the name. S for SimpleBox/StackBox, or maybe could do VBox?
#[repr(transparent)]
pub struct SBox<T: ?Sized>(T);

pub type Volatile<T, A> = VolatileRef<SBox<T>, A>;

impl<T> Volatile<T> {
    pub const fn new(value: T) -> Self;
}
impl<T> Volatile<T, ReadOnly> {
    pub const fn new_read_only(value: T) -> Self;
}
impl<T> Volatile<T, WriteOnly> {
    pub const fn new_write_only(value: T) -> Self;
}

I'm totally not sold on any of the naming, but I think the basic idea of Volatile<T, A>/VolatileRef<R, A> is pretty good.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions