Skip to content

Commit

Permalink
Add String::bump method
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfbacon committed Jan 9, 2023
1 parent c6507f7 commit 3664dbb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/collections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3664dbb

Please sign in to comment.