diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
commit | 837b550238aa671a591ccf282dddeab29cadb206 (patch) | |
tree | 914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/bumpalo/src/collections | |
parent | Adding debian version 1.70.0+dfsg2-1. (diff) | |
download | rustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz rustc-837b550238aa671a591ccf282dddeab29cadb206.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/bumpalo/src/collections')
-rw-r--r-- | vendor/bumpalo/src/collections/string.rs | 18 | ||||
-rw-r--r-- | vendor/bumpalo/src/collections/vec.rs | 20 |
2 files changed, 38 insertions, 0 deletions
diff --git a/vendor/bumpalo/src/collections/string.rs b/vendor/bumpalo/src/collections/string.rs index 6b7af9a4b..ffd1db92d 100644 --- a/vendor/bumpalo/src/collections/string.rs +++ b/vendor/bumpalo/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. diff --git a/vendor/bumpalo/src/collections/vec.rs b/vendor/bumpalo/src/collections/vec.rs index b5a60029e..312aa055b 100644 --- a/vendor/bumpalo/src/collections/vec.rs +++ b/vendor/bumpalo/src/collections/vec.rs @@ -675,6 +675,26 @@ impl<'bump, T: 'bump> Vec<'bump, T> { } } + /// Returns a shared reference to the allocator backing this `Vec`. + /// + /// # Examples + /// + /// ``` + /// use bumpalo::{Bump, collections::Vec}; + /// + /// // uses the same allocator as the provided `Vec` + /// fn add_strings<'bump>(vec: &mut Vec<'bump, &'bump str>) { + /// for string in ["foo", "bar", "baz"] { + /// vec.push(vec.bump().alloc_str(string)); + /// } + /// } + /// ``` + #[inline] + #[must_use] + pub fn bump(&self) -> &'bump Bump { + self.buf.bump() + } + /// Returns the number of elements the vector can hold without /// reallocating. /// |