pub struct StrStack { /* private fields */ }Implementations§
Source§impl StrStack
impl StrStack
pub fn new() -> Self
Sourcepub fn with_capacity(items: usize, bytes: usize) -> Self
pub fn with_capacity(items: usize, bytes: usize) -> Self
Creates a new StrStack with pre-allocated capacity for items string segments
and bytes total bytes of string data.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn bytes_len(&self) -> u32
pub fn bytes_len(&self) -> u32
Returns the total byte length of the data buffer.
Returns u32 to match the internal boundary representation,
making the 4 GB limit explicit at the call site.
Sourcepub fn reserve_items(&mut self, additional: usize)
pub fn reserve_items(&mut self, additional: usize)
Reserves capacity for at least additional more string segments.
Sourcepub fn reserve_bytes(&mut self, additional: usize)
pub fn reserve_bytes(&mut self, additional: usize)
Reserves capacity for at least additional more bytes of string data.
pub fn as_str(&self) -> &str
pub fn get(&self, index: usize) -> Option<&str>
Sourcepub unsafe fn get_unchecked(&self, begin: usize, end: usize) -> &str
👎Deprecated: Use get() instead. This will be removed in a future version.
pub unsafe fn get_unchecked(&self, begin: usize, end: usize) -> &str
Use get() instead. This will be removed in a future version.
Returns a &str slice without bounds checks.
§Safety
begin <= endend <= self.data.len()self.data[begin..end]must be valid UTF-8
pub fn get_bounds(&self, index: usize) -> Option<(u32, u32)>
pub fn get_top(&self) -> Option<&str>
Sourcepub fn last(&self) -> Option<&str>
pub fn last(&self) -> Option<&str>
Returns the last (topmost) string segment, or None if empty.
Alias for get_top.
pub fn remove_top(&mut self) -> Option<()>
pub fn pop_owned<T>(&mut self) -> Option<T>
pub fn push(&mut self, s: &str)
Sourcepub fn try_push(&mut self, s: &str) -> Result<(), StrStackOverflow>
pub fn try_push(&mut self, s: &str) -> Result<(), StrStackOverflow>
Fallible push: appends a string segment, returning Err if the total byte
length would exceed u32::MAX.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all string segments, resetting the stack to empty.
Does not release allocated memory (use shrink_to_fit on the underlying
vecs if needed — not yet exposed).
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Keeps the first len string segments and removes the rest.
If len >= self.len(), this is a no-op (matches Vec::truncate semantics).
Sourcepub fn checkpoint(&self) -> Checkpoint
pub fn checkpoint(&self) -> Checkpoint
Captures a lightweight checkpoint of the current stack state.
The checkpoint can later be passed to reset to roll back
any segments pushed after this point. Useful for speculative parsing:
push tokens tentatively, then either commit (by discarding the checkpoint)
or roll back (by calling reset).
Sourcepub fn reset(&mut self, cp: Checkpoint)
pub fn reset(&mut self, cp: Checkpoint)
Rolls the stack back to a previously captured Checkpoint.
Removes all segments pushed after the checkpoint was taken.
§Panics
Panics if the checkpoint is invalid (its item count or byte count exceeds
the current stack state). This can happen if the checkpoint was created from
a different StrStack, or if the stack was reset to an earlier checkpoint
after this one was taken.