Move example code from README.md to lib.rs
crates.io cannot hide portions of the example when marking the line
using hashtag in README.md. Moving the example into the doc comment of
lib.rs where it is formatted correctly on docs.rs.
Change-Id: I7bd4fec944813b7f0270e7deccbb05377b60cf89
Signed-off-by: Imre Kis <imre.kis@arm.com>
diff --git a/Cargo.lock b/Cargo.lock
index 7a750c7..6951a77 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,7 +4,7 @@
[[package]]
name = "arm-sp805"
-version = "0.1.0"
+version = "0.1.1"
dependencies = [
"bitflags",
"safe-mmio",
diff --git a/Cargo.toml b/Cargo.toml
index f184a8e..7daf4e0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,7 +3,7 @@
[package]
name = "arm-sp805"
-version = "0.1.0"
+version = "0.1.1"
authors = [
"Balint Dobszay <balint.dobszay@arm.com>",
"Imre Kis <imre.kis@arm.com>",
diff --git a/README.md b/README.md
index 9f4fb11..6e7deaa 100644
--- a/README.md
+++ b/README.md
@@ -7,30 +7,6 @@
* Enable/disable watchdog timer
* Update timer value
-## Example
-
-```rust
-use arm_sp805::{SP805Registers, Watchdog, UniqueMmioPointer};
-use core::ptr::NonNull;
-# use zerocopy::transmute_mut;
-# let mut fake_registers = [0u32; 1024];
-# let WATCHDOG_ADDRESS : *mut SP805Registers = transmute_mut!(&mut fake_registers);
-# fn handler() {}
-
-// SAFETY: `WATCHDOG_ADDRESS` is the base address of a SP805 watchdog register block. It remains
-// valid for the lifetime of the application and nothing else references this address range.
-let watchdog_pointer = unsafe { UniqueMmioPointer::new(NonNull::new(WATCHDOG_ADDRESS).unwrap()) };
-
-let mut watchdog = Watchdog::new(watchdog_pointer, 0x0001_0000);
-watchdog.enable();
-
-loop {
- handler();
- watchdog.update();
- # break
-}
-```
-
## License
The project is MIT and Apache-2.0 dual licensed, see `LICENSE-APACHE` and `LICENSE-MIT`.
diff --git a/src/lib.rs b/src/lib.rs
index b328a86..2540880 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,6 +5,29 @@
#![doc = include_str!("../README.md")]
#![deny(clippy::undocumented_unsafe_blocks)]
+//! ## Example
+//! ```rust
+//! use arm_sp805::{SP805Registers, Watchdog, UniqueMmioPointer};
+//! use core::ptr::NonNull;
+//! # use zerocopy::transmute_mut;
+//! # let mut fake_registers = [0u32; 1024];
+//! # let WATCHDOG_ADDRESS : *mut SP805Registers = transmute_mut!(&mut fake_registers);
+//! # fn handler() {}
+//!
+//! // SAFETY: `WATCHDOG_ADDRESS` is the base address of a SP805 watchdog register block. It remains
+//! // valid for the lifetime of the application and nothing else references this address range.
+//! let watchdog_pointer = unsafe { UniqueMmioPointer::new(NonNull::new(WATCHDOG_ADDRESS).unwrap()) };
+//!
+//! let mut watchdog = Watchdog::new(watchdog_pointer, 0x0001_0000);
+//! watchdog.enable();
+//!
+//! loop {
+//! handler();
+//! watchdog.update();
+//! # break
+//! }
+//! ```
+
use bitflags::bitflags;
pub use safe_mmio::UniqueMmioPointer;
use safe_mmio::{