|
71 | 71 | //! ```
|
72 | 72 | //!
|
73 | 73 | //! Once your API uses [`nb::Result`] you can leverage the [`block!`], macro
|
74 |
| -//! to adapt it for blocking operation, or handle scheduling yourself. |
| 74 | +//! to adapt it for blocking operation, or handle scheduling yourself. You can |
| 75 | +//! also use the [`fut!`] macro to use it in an async/await context |
75 | 76 | //!
|
76 | 77 | //! [`block!`]: macro.block.html
|
| 78 | +//! [`fut!`]: macro.fut.html |
77 | 79 | //! [`nb::Result`]: type.Result.html
|
78 | 80 | //!
|
79 | 81 | //! # Examples
|
|
182 | 184 | //! # }
|
183 | 185 | //! # }
|
184 | 186 | //! ```
|
| 187 | +//! ## Future mode |
| 188 | +//! |
| 189 | +//! Turn on an LED for one second and *then* loops back serial data. |
| 190 | +//! |
| 191 | +//! ``` |
| 192 | +//! use core::convert::Infallible; |
| 193 | +//! use nb::fut; |
| 194 | +//! |
| 195 | +//! use hal::{Led, Serial, Timer}; |
| 196 | +//! |
| 197 | +//! # async fn run() -> Result<(), Infallible>{ |
| 198 | +//! Led.on(); |
| 199 | +//! fut!(Timer.wait()).await; |
| 200 | +//! Led.off(); |
| 201 | +//! loop { |
| 202 | +//! let byte = fut!(Serial.read()).await?; |
| 203 | +//! fut!(Serial.write(byte)).await?; |
| 204 | +//! } |
| 205 | +//! # } |
| 206 | +//! |
| 207 | +//! # mod hal { |
| 208 | +//! # use nb; |
| 209 | +//! # use core::convert::Infallible; |
| 210 | +//! # pub struct Led; |
| 211 | +//! # impl Led { |
| 212 | +//! # pub fn off(&self) {} |
| 213 | +//! # pub fn on(&self) {} |
| 214 | +//! # } |
| 215 | +//! # pub struct Serial; |
| 216 | +//! # impl Serial { |
| 217 | +//! # pub fn read(&self) -> nb::Result<u8, Infallible> { Ok(0) } |
| 218 | +//! # pub fn write(&self, _: u8) -> nb::Result<(), Infallible> { Ok(()) } |
| 219 | +//! # } |
| 220 | +//! # pub struct Timer; |
| 221 | +//! # impl Timer { |
| 222 | +//! # pub fn wait(&self) -> nb::Result<(), Infallible> { Ok(()) } |
| 223 | +//! # } |
| 224 | +//! # } |
185 | 225 |
|
186 | 226 | #![no_std]
|
187 | 227 | #![doc(html_root_url = "https://docs.rs/nb/1.0.0")]
|
|
0 commit comments