From 7e959054e4d39cba4a8c0313e31f39f537f74695 Mon Sep 17 00:00:00 2001 From: Alex Martens Date: Sun, 9 Mar 2025 12:54:08 -0700 Subject: [PATCH] lib.rs: remove unwrap from example This follows the C-QUESTION-MARK API guideline. Also we had missed an unwrap on one of the push calls. --- src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3646e31c..bc75b8cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ //! //! // on the stack //! let mut xs: Vec = Vec::new(); // can hold up to 8 elements -//! xs.push(42).unwrap(); +//! xs.push(42)?; //! assert_eq!(xs.pop(), Some(42)); //! //! // in a `static` variable @@ -21,13 +21,14 @@ //! //! let xs = unsafe { &mut XS }; //! -//! xs.push(42); +//! xs.push(42)?; //! assert_eq!(xs.pop(), Some(42)); //! //! // in the heap (though kind of pointless because no reallocation) //! let mut ys: Box> = Box::new(Vec::new()); -//! ys.push(42).unwrap(); +//! ys.push(42)?; //! assert_eq!(ys.pop(), Some(42)); +//! # Ok::<(), u8>(()) //! ``` //! //! Because they have fixed capacity `heapless` data structures don't implicitly reallocate. This