Skip to content

Commit 3dd3650

Browse files
authored
Merge pull request #190 from mattfbacon/main
Add String::bump
2 parents 701514f + 37be9a9 commit 3dd3650

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/collections/string.rs

+18
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,24 @@ impl<'bump> String<'bump> {
798798
String { vec: bytes }
799799
}
800800

801+
/// Returns a shared reference to the allocator backing this `String`.
802+
///
803+
/// # Examples
804+
///
805+
/// ```
806+
/// use bumpalo::{Bump, collections::String};
807+
///
808+
/// // uses the same allocator as the provided `String`
809+
/// fn copy_string<'bump>(s: &String<'bump>) -> &'bump str {
810+
/// s.bump().alloc_str(s.as_str())
811+
/// }
812+
/// ```
813+
#[inline]
814+
#[must_use]
815+
pub fn bump(&self) -> &'bump Bump {
816+
self.vec.bump()
817+
}
818+
801819
/// Converts a `String` into a byte vector.
802820
///
803821
/// This consumes the `String`, so we do not need to copy its contents.

0 commit comments

Comments
 (0)