Skip to content

Commit

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

Please sign in to comment.