Skip to content

Commit

Permalink
Add Vec::bump method
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfbacon committed Jan 6, 2023
1 parent b1e67b7 commit c6507f7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/collections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,26 @@ impl<'bump, T: 'bump> Vec<'bump, T> {
}
}

/// Returns a shared reference to the allocator backing this `Vec`.
///
/// # Examples
///
/// ```
/// use bumpalo::{Bump, collections::Vec};
///
/// // uses the same allocator as the provided `Vec`
/// fn add_strings<'bump>(vec: &mut Vec<'bump, &'bump str>) {
/// for string in ["foo", "bar", "baz"] {
/// vec.push(vec.bump().alloc_str(string));
/// }
/// }
/// ```
#[inline]
#[must_use]
pub fn bump(&self) -> &'bump Bump {
self.buf.bump()
}

/// Returns the number of elements the vector can hold without
/// reallocating.
///
Expand Down

0 comments on commit c6507f7

Please sign in to comment.