Skip to content

New design based on *mut T #22

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

Merged
merged 17 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ repository = "https://github.com/rust-osdev/volatile"
# Enable unstable features; requires Rust nightly; might break on compiler updates
unstable = []

[dev-dependencies]
rand = "0.8.3"

[package.metadata.release]
no-dev-version = true
pre-release-replacements = [
Expand Down
38 changes: 36 additions & 2 deletions src/access.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
pub trait Access {}

/// Helper trait that is implemented by [`ReadWrite`] and [`ReadOnly`].
pub trait Readable {}
pub trait Readable: UnsafelyReadable {}

/// Helper trait that is implemented by [`ReadWrite`] and [`WriteOnly`].
pub trait Writable {}
pub trait Writable: UnsafelyWritable {}

pub trait UnsafelyReadable {}

pub trait UnsafelyWritable {}

/// Zero-sized marker type for allowing both read and write access.
#[derive(Debug, Copy, Clone)]
pub struct ReadWrite;
impl Access for ReadWrite {}
impl Readable for ReadWrite {}
impl UnsafelyReadable for ReadWrite {}
impl Writable for ReadWrite {}
impl UnsafelyWritable for ReadWrite {}

/// Zero-sized marker type for allowing only read access.
#[derive(Debug, Copy, Clone)]
pub struct ReadOnly;

impl Access for ReadOnly {}
impl Readable for ReadOnly {}
impl UnsafelyReadable for ReadOnly {}

/// Zero-sized marker type for allowing only write access.
#[derive(Debug, Copy, Clone)]
pub struct WriteOnly;

impl Access for WriteOnly {}
impl Writable for WriteOnly {}
impl UnsafelyWritable for WriteOnly {}

#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Custom<R, W> {
pub read: R,
pub write: W,
}

#[derive(Clone, Copy, PartialEq, Eq)]
pub struct NoAccess;
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct SafeAccess;
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct UnsafeAccess;

impl<W> Readable for Custom<SafeAccess, W> {}
impl<W> UnsafelyReadable for Custom<SafeAccess, W> {}
impl<W> UnsafelyReadable for Custom<UnsafeAccess, W> {}
impl<R> Writable for Custom<R, SafeAccess> {}
impl<R> UnsafelyWritable for Custom<R, SafeAccess> {}
impl<R> UnsafelyWritable for Custom<R, UnsafeAccess> {}
Loading