From 3664dbb7922fa1372adf53fb8767cd0fc2115267 Mon Sep 17 00:00:00 2001 From: Matt Fellenz Date: Mon, 9 Jan 2023 13:06:38 -0800 Subject: [PATCH] Add String::bump method --- src/collections/string.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/collections/string.rs b/src/collections/string.rs index 6b7af9a..ffd1db9 100644 --- a/src/collections/string.rs +++ b/src/collections/string.rs @@ -798,6 +798,24 @@ impl<'bump> String<'bump> { String { vec: bytes } } + /// Returns a shared reference to the allocator backing this `String`. + /// + /// # Examples + /// + /// ``` + /// use bumpalo::{Bump, collections::String}; + /// + /// // uses the same allocator as the provided `String` + /// fn copy_string<'bump>(s: &String<'bump>) -> &'bump str { + /// s.bump().alloc_str(s.as_str()) + /// } + /// ``` + #[inline] + #[must_use] + pub fn bump(&self) -> &'bump Bump { + self.vec.bump() + } + /// Converts a `String` into a byte vector. /// /// This consumes the `String`, so we do not need to copy its contents.