Skip to content

Commit

Permalink
Merge pull request #189 from mattfbacon/main
Browse files Browse the repository at this point in the history
Add Vec::bump method
  • Loading branch information
fitzgen authored Jan 9, 2023
2 parents b1e67b7 + c6507f7 commit 701514f
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 701514f

Please sign in to comment.