Skip to content

Commit 701514f

Browse files
authored
Merge pull request #189 from mattfbacon/main
Add Vec::bump method
2 parents b1e67b7 + c6507f7 commit 701514f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/collections/vec.rs

+20
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,26 @@ impl<'bump, T: 'bump> Vec<'bump, T> {
675675
}
676676
}
677677

678+
/// Returns a shared reference to the allocator backing this `Vec`.
679+
///
680+
/// # Examples
681+
///
682+
/// ```
683+
/// use bumpalo::{Bump, collections::Vec};
684+
///
685+
/// // uses the same allocator as the provided `Vec`
686+
/// fn add_strings<'bump>(vec: &mut Vec<'bump, &'bump str>) {
687+
/// for string in ["foo", "bar", "baz"] {
688+
/// vec.push(vec.bump().alloc_str(string));
689+
/// }
690+
/// }
691+
/// ```
692+
#[inline]
693+
#[must_use]
694+
pub fn bump(&self) -> &'bump Bump {
695+
self.buf.bump()
696+
}
697+
678698
/// Returns the number of elements the vector can hold without
679699
/// reallocating.
680700
///

0 commit comments

Comments
 (0)