Skip to content

Commit

Permalink
lib/picotoml: use heapless::vec to allow usage without alloc (#1)
Browse files Browse the repository at this point in the history
Signed-off-by: Junxing Zhu <[email protected]>
  • Loading branch information
luojia65 authored Feb 10, 2025
2 parents cf06989 + 449cf7d commit 478750c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/picotoml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
[dependencies]
logos = { version = "0.13.0", default-features = false, features = ["export_derive"] }
serde = { version = "1.0.188", default-features = false }
arrayvec = "0.7.6"
heapless = "0.8.0"

[features]
default = []
Expand Down
5 changes: 4 additions & 1 deletion lib/picotoml/src/peeking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct PeekingIterator<I: Iterator> {
#[cfg(feature = "alloc")]
queue: alloc::vec::Vec<Option<I::Item>>,
#[cfg(not(feature = "alloc"))]
queue: arrayvec::ArrayVec<Option<I::Item>, DEFAULT_STACK_SIZE>,
queue: heapless::Vec<Option<I::Item>, DEFAULT_STACK_SIZE>,

/// The cursor points to the element we are currently peeking at.
///
Expand Down Expand Up @@ -85,7 +85,10 @@ impl<I: Iterator> PeekingIterator<I> {
#[inline]
fn push_next_to_queue(&mut self) {
let item = self.iterator.next();
#[cfg(feature = "alloc")]
self.queue.push(item);
#[cfg(not(feature = "alloc"))]
self.queue.push(item).ok();
}

/// Increment the cursor which points to the current peekable item.
Expand Down

0 comments on commit 478750c

Please sign in to comment.