From 6cd82c63cde438fc0773744ca12cd2bb9208c05c Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Mon, 10 Feb 2020 15:32:07 +0100 Subject: [PATCH] Enhance the Mmio API, and deprecate Mmio::new(). --- src/io/mmio.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/io/mmio.rs b/src/io/mmio.rs index f212636..42251ad 100644 --- a/src/io/mmio.rs +++ b/src/io/mmio.rs @@ -11,9 +11,23 @@ pub struct Mmio { impl Mmio { /// Create a new Mmio without initializing + #[deprecated = "unsound because it's possible to read even though it's uninitialized"] pub fn new() -> Self { - Mmio { - value: MaybeUninit::uninit() + unsafe { Self::uninit() } + } + pub unsafe fn zeroed() -> Self { + Self { + value: MaybeUninit::zeroed(), + } + } + pub unsafe fn uninit() -> Self { + Self { + value: MaybeUninit::uninit(), + } + } + pub const fn from(value: T) -> Self { + Self { + value: MaybeUninit::new(value), } } }