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.
This commit is contained in:
Alex Martens 2025-03-09 12:54:08 -07:00
parent 2e71c18252
commit 7e959054e4

View File

@ -13,7 +13,7 @@
//!
//! // on the stack
//! let mut xs: Vec<u8, 8> = 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<Vec<u8, 8>> = 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