8000 Rewrite crate to operate on reference values by phil-opp · Pull Request #13 · rust-osdev/volatile · GitHub
[go: up one dir, main page]

Skip to content

Rewrite crate to operate on reference values #13

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 31 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
277b25b
Different rewrite approaches
phil-opp Jul 29, 2020
93fb1e1
Decide for foo.rs approach
phil-opp Jul 29, 2020
8be4430
Update documentation
phil-opp Jul 29, 2020
401a86b
Remove const_fn cargo feature
phil-opp Jul 29, 2020
59dd91d
Reorganize access module and make it public
phil-opp Jul 29, 2020
53fd257
Add constructor methods for read/write-only types
phil-opp Jul 29, 2020
b469f42
Make methods generic using `Deref` trait
phil-opp Jul 29, 2020
d0bcea2
Add methods for working with volatile slices
phil-opp Jul 29, 2020
1b4931d
Document `copy_into_slice` method
phil-opp Jul 29, 2020
4766a43
Add `as_slice`/`as_mut_slice` methods for volatile array references
phil-opp Jul 30, 2020
cfbd66e
Rename the 'nightly' feature to 'unstable'
phil-opp Jul 31, 2020
bf8031c
Document constructor functions
phil-opp Jul 31, 2020
93e7150
Provide a custom fmt::Debug implementation to prevent reading of writ…
phil-opp Jul 31, 2020
8682a86
Improve documentation of `Volatile::new`
phil-opp Jul 31, 2020
46a7603
Warn on missing documentation
phil-opp Jul 31, 2020
7dffe2c
Improve documentation
phil-opp Aug 19, 2020
dfbaa68
Run cargo fmt
phil-opp Aug 19, 2020
76e7657
Don't derive Default
phil-opp Aug 19, 2020
4ba88d3
Add `map`/`map_mut`/`extract_inner` methods
phil-opp Aug 19, 2020
fb7e6a5
Use map/map_mut for index/index_mut implementation
phil-opp Aug 19, 2020
a78fd04
Use map/map_mut for array to slice conversion methods
phil-opp Aug 19, 2020
eabda2e
Add documentation for slice index methods
phil-opp Aug 19, 2020
2e272d6
Fix typo in docs
phil-opp Aug 19, 2020
d120638
Change order of impl blocks to show `read`/`write` methods first in docs
phil-opp Aug 19, 2020
966bea9
Enable `unstable` feature when building docs on docs.rs
phil-opp Aug 19, 2020
408a5f1
Create a CI workflow
phil-opp Aug 19, 2020
9bc9f95
Fix as_slice/as_mut_slice
phil-opp Aug 19, 2020
267ef61
Add `fill` and `copy_within` methods for slices
phil-opp Sep 9, 2020
401c5ba
Derive `Debug` and `Clone` for access types
phil-opp Sep 21, 2020
a4ccd3d
Document new slice methods
phil-opp Sep 21, 2020
2eaa1d6
Update check_range call for latest nightly
phil-opp Sep 21, 2020
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
Prev Previous commit
Next Next commit
Improve documentation
  • Loading branch information
phil-opp committed Aug 19, 2020
commit 7dffe2cbf16120d6db65438311f665345a2149c2
6 changes: 6 additions & 0 deletions src/access.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
/// Helper trait that is implemented by [`ReadWrite`] and [`ReadOnly`].
pub trait Readable {}

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

/// Zero-sized marker type for allowing both read and write access.
pub struct ReadWrite;
impl Readable for ReadWrite {}
impl Writable for ReadWrite {}

/// Zero-sized marker type for allowing only read access.
pub struct ReadOnly;

impl Readable for ReadOnly {}

/// Zero-sized marker type for allowing only write access.
pub struct WriteOnly;
impl Writable for WriteOnly {}
21 changes: 13 additions & 8 deletions src/lib.rs
5C96
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! by the compiler, and are useful in many low-level systems programming and concurrent contexts.
//!
//! The wrapper types *do not* enforce any atomicity guarantees; to also get atomicity, consider
//! looking at the `Atomic` wrapper type found in `libcore` or `libstd`.
//! looking at the `Atomic` wrapper types found in `libcore` or `libstd`.
//!
//! These wrappers do not depend on the standard library and never panic.

Expand All @@ -28,22 +28,26 @@ use core::{
/// Allows creating read-only and write-only `Volatile` values.
pub mod access;

/// A wrapper type around a reference to a volatile variable.
/// Wraps a reference to make accesses to referenced value volatile.
///
/// Allows volatile reads and writes on the referenced value. The referenced value needs to
/// be `Copy`, as volatile reads and writes take and return copies of the value.
/// be `Copy` for reading and writing, as volatile reads and writes take and return copies
/// of the value.
///
/// The size of this struct is the same as the size of the contained type.
/// Since not all volatile resources (e.g. memory mapped device registers) are both readable
/// and writable, this type supports limiting the allowed access types through an optional second
/// generic parameter `A` that can be one of `ReadWrite`, `ReadOnly`, or `WriteOnly`. It defaults
/// to `ReadWrite`, which allows all operations.
///
/// TODO: read/write permissions
/// The size of this struct is the same as the size of the contained reference.
#[derive(Default, Clone)]
#[repr(transparent)]
pub struct Volatile<R, A = ReadWrite> {
reference: R,
access: PhantomData<A>,
}

/// Constructor functions
/// Constructor functions for creating new values
///
/// These functions allow to construct a new `Volatile` instance from a reference type. While
/// the `new` function creates a `Volatile` instance with unrestricted access, there are also
Expand Down Expand Up @@ -164,7 +168,8 @@ where
///
/// Returns a copy of the read value. Volatile reads are guaranteed not to be optimized
/// away by the compiler, but by themselves do not have atomic ordering
/// guarantees. To also get atomicity, consider looking at the `Atomic` wrapper type.
/// guarantees. To also get atomicity, consider looking at the `Atomic` wrapper types of
/// the standard/`core` library.
///
/// ## Examples
///
Expand All @@ -191,7 +196,7 @@ where
///
/// Volatile writes are guaranteed to not be optimized away by the compiler, but by
/// themselves do not have atomic ordering guarantees. To also get atomicity, consider
/// looking at the `Atomic` wrapper type.
/// looking at the `Atomic` wrapper types of the standard/`core` library.
///
/// ## Example
///
Expand Down
0