pub struct BumpBox<'a, T: ?Sized> { /* private fields */ }
Expand description
A pointer type that uniquely owns a bump allocation of type T
. This type is returned whenever a bump allocation is made.
You can turn a BumpBox
into a reference with into_ref
and into_mut
and into a Box
with into_box
.
Unlike Box
, BumpBox
cannot implement Clone
or free the allocated space on drop,
as it does not store its allocator. It’s essentially just an owned reference.
A BumpBox
can be deallocated using Bump(Scope)::dealloc
.
§BumpBox
has a lot of methods
BumpBox<[T]>
provides methods fromVec<T>
likepop
,clear
,truncate
,remove
,swap_remove
,retain
,drain
,extract_if
,dedup
, slice methods but with owned semantics likesplit_at
,split_first
,split_last
and additional methods likesplit_off
,partition
andmap_in_place
.BumpBox<str>
provide methods fromString
likefrom_utf8(_unchecked)
,into_boxed_bytes
,as_mut_bytes
,pop
,truncate
,clear
,remove
,retain
,drain
andsplit_off
.BumpBox<MaybeUninit<T>>
andBumpBox<[MaybeUninit<T>]>
provide methods likeinit
,assume_init
,init_fill
,init_fill_with
,init_fill_iter
,init_copy
,init_clone
andinit_zeroed
.
§Api differences
BumpBox<[T]>
and BumpBox<str>
mirror the api of vectors and strings respectively.
As such, methods like as_ptr
and as_mut_ptr
return a pointer to the start of the slice
instead of a slice pointer. To get a pointer to the boxed content T
of BumpBox<T>
,
use as_raw
instead.
Unlike Box<T>
, BumpBox<T>
has some methods that are implemented for all T
.
Care is taken to not overwrite methods of T
by only adding methods that start with
into_
. By convention into_*
methods consume the type, so if T
has an into_*
method, then that method would not be callable through on BumpBox<T>
but would
require you to call into_inner
first.
§No pinning
There is no way to safely pin a BumpBox
in the general case.
The drop guarantee of Pin
requires the value to be dropped before its memory is reused.
Preventing reuse of memory is not an option as that’s what this crate is all about.
So we need to drop the pinned value.
But there is no way to ensure that a value is dropped in an async context.
Example of an unsound pin macro implementation.
We define a bump_box_pin
macro that turns a BumpBox<T>
into a Pin<&mut T>
. This is only sound in synchronous code.
Here the memory Foo(1)
is allocated at is reused by Foo(2)
without dropping Foo(1)
first which violates the drop guarantee.
macro_rules! bump_box_pin {
($name:ident) => {
let mut boxed: BumpBox<_> = $name;
let $name = unsafe { Pin::new_unchecked(&mut *boxed) };
};
}
struct Foo(i32);
impl Drop for Foo {
fn drop(&mut self) {
println!("dropped Foo({}) at {:?}", self.0, self as *const Foo);
}
}
fn use_pinned(_foo: Pin<&mut Foo>) {}
fn violate_drop_guarantee(cx: &mut Context) {
let mut bump: Bump = Bump::new();
let mut future = Box::pin(async {
let foo = bump.alloc(Foo(1));
println!("created Foo({}) at {:?}", foo.0, &*foo as *const Foo);
bump_box_pin!(foo);
println!("pinned Foo({}) at {:?}", foo.0, &*foo as *const Foo);
yield_now().await;
use_pinned(foo);
});
assert_eq!(future.as_mut().poll(cx), Poll::Pending);
mem::forget(future);
bump.reset();
let foo = bump.alloc(Foo(2));
println!("created Foo({}) at {:?}", foo.0, &*foo as *const Foo);
}
This will print something like:
created Foo(1) at 0x78a4f4000d30
pinned Foo(1) at 0x78a4f4000d30
created Foo(2) at 0x78a4f4000d30
dropped Foo(2) at 0x78a4f4000d30
Implementations§
Source§impl<'a, T: ?Sized> BumpBox<'a, T>
impl<'a, T: ?Sized> BumpBox<'a, T>
Sourcepub fn into_box<A, B>(self, allocator: A) -> Bwhere
A: BumpAllocatorScope<'a>,
B: BoxLike<T = T, A = A>,
pub fn into_box<A, B>(self, allocator: A) -> Bwhere
A: BumpAllocatorScope<'a>,
B: BoxLike<T = T, A = A>,
Turns this BumpBox<T>
into Box<T>
. The bump
allocator is not required to be
the allocator this box was allocated in.
Unlike BumpBox
, Box
implements Clone
and frees space iff it is the last allocation:
let a: Box<_, _> = bump.alloc(3i32).into_box(&bump);
let b = a.clone();
assert_eq!(a, b);
drop(b);
drop(a);
assert_eq!(bump.stats().allocated(), 0);
Sourcepub fn leak(boxed: Self) -> &'a mut T
pub fn leak(boxed: Self) -> &'a mut T
Turns this BumpBox<T>
into &mut T
that is live for this bump scope.
T
won’t be dropped which may leak resources.
If T
is NoDrop
, prefer to call into_mut
to signify that nothing gets leaked.
§Examples
let boxed_slice_of_slices: BumpBox<[&mut [i32]]> = bump.alloc_iter_exact((0..3).map(|_| {
bump.alloc_slice_fill_with(3, Default::default).into_mut()
}));
// `&mut T` don't implement `NoDrop` even though they should
// (the blanket implementation `impl<T: Copy> NoDrop for T {}` prevents us from implementing it)
// so we need to use `leak`
let slice_of_slices: &mut [&mut [i32]] = BumpBox::leak(boxed_slice_of_slices);
Sourcepub const fn as_raw(b: &Self) -> NonNull<T>
pub const fn as_raw(b: &Self) -> NonNull<T>
Returns a NonNull
pointer to the BumpBox
’s contents.
The caller must ensure that the BumpBox
outlives the pointer this
function returns, or else it will end up dangling.
This method guarantees that for the purpose of the aliasing model, this method
does not materialize a reference to the underlying memory, and thus the returned pointer
will remain valid when mixed with other calls to as_raw
and into_raw
.
Note that calling other methods that materialize references to the memory
may still invalidate this pointer.
See the example below for how this guarantee can be used.
§Examples
Due to the aliasing guarantee, the following code is legal:
unsafe {
let b = bump.alloc(0);
let ptr1 = BumpBox::as_raw(&b);
ptr1.write(1);
let ptr2 = BumpBox::as_raw(&b);
ptr2.write(2);
// Notably, the write to `ptr2` did *not* invalidate `ptr1`:
ptr1.write(3);
}
Sourcepub fn into_raw(self) -> NonNull<T>
pub fn into_raw(self) -> NonNull<T>
Consumes the BumpBox
, returning a wrapped raw pointer.
The pointer will be properly aligned and non-null. It is only valid for the lifetime 'a
.
After calling this function, the caller is responsible for dropping the
value previously managed by the BumpBox
. The easiest way to do this is to p.drop_in_place()
.
You can turn this pointer back into a BumpBox
with BumpBox::from_raw
.
§Examples
Manually dropping T
:
use bump_scope::{Bump, BumpBox};
let bump: Bump = Bump::new();
let x = bump.alloc(String::from("Hello"));
let p = BumpBox::into_raw(x);
unsafe { p.as_ptr().drop_in_place() }
Sourcepub unsafe fn from_raw(ptr: NonNull<T>) -> Self
pub unsafe fn from_raw(ptr: NonNull<T>) -> Self
Constructs a BumpBox
from a raw pointer.
After calling this function, the pointed to value is owned by the resulting BumpBox
.
Specifically, the BumpBox
destructor will call the destructor of T
.
For this to be safe, the pointer must point to a valid T
for the lifetime of 'a
.
§Safety
ptr
must point to a valid value for the lifetime'a
§Examples
Recreate a BumpBox
which was previously converted to a raw pointer
using BumpBox::into_raw
:
use bump_scope::{Bump, BumpBox};
use core::ptr::NonNull;
unsafe fn from_raw_in<'a, T>(ptr: NonNull<T>, bump: &'a Bump) -> BumpBox<'a, T> {
BumpBox::from_raw(ptr)
}
let bump: Bump = Bump::new();
let x = bump.alloc(String::from("Hello"));
let ptr = BumpBox::into_raw(x);
let x = unsafe { from_raw_in(ptr, &bump) };
assert_eq!(x.as_str(), "Hello");
drop(x);
Manually create a BumpBox
from scratch by using the bump allocator:
use bump_scope::{Bump, BumpBox};
use core::alloc::Layout;
use core::ptr::NonNull;
unsafe fn from_raw_in<'a, T>(ptr: NonNull<T>, bump: &'a Bump) -> BumpBox<'a, T> {
BumpBox::from_raw(ptr)
}
let bump: Bump = Bump::new();
let five = unsafe {
let ptr = bump.alloc_layout(Layout::new::<i32>());
// In general .write is required to avoid attempting to destruct
// the (uninitialized) previous contents of `ptr`, though for this
// simple example `*ptr = 5` would have worked as well.
ptr.as_ptr().write(5);
from_raw_in(ptr, &bump)
};
assert_eq!(*five, 5);
Source§impl<'a, T> BumpBox<'a, T>
impl<'a, T> BumpBox<'a, T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the BumpBox
, returning the wrapped value.
§Examples
let c = bump.alloc(5);
assert_eq!(c.into_inner(), 5);
Sourcepub fn into_boxed_slice(self) -> BumpBox<'a, [T]> ⓘ
pub fn into_boxed_slice(self) -> BumpBox<'a, [T]> ⓘ
Converts a BumpBox<T>
into a BumpBox<[T]>
This conversion happens in place.
Source§impl<'a> BumpBox<'a, str>
impl<'a> BumpBox<'a, str>
Sourcepub const fn from_utf8(
bytes: BumpBox<'a, [u8]>,
) -> Result<Self, FromUtf8Error<BumpBox<'a, [u8]>>>
pub const fn from_utf8( bytes: BumpBox<'a, [u8]>, ) -> Result<Self, FromUtf8Error<BumpBox<'a, [u8]>>>
Converts a BumpBox<[u8]>
to a BumpBox<str>
.
A string (BumpBox<str>
) is made of bytes (u8
), and a vector of bytes
([BumpBox<[u8]>
]) is made of bytes, so this function converts between the
two. Not all byte slices are valid BumpBox<str>
s, however: BumpBox<str>
requires that it is valid UTF-8. from_utf8()
checks to ensure that
the bytes are valid UTF-8, and then does the conversion.
If you are sure that the byte slice is valid UTF-8, and you don’t want
to incur the overhead of the validity check, there is an unsafe version
of this function, from_utf8_unchecked
, which has the same behavior
but skips the check.
This method will take care to not copy the vector, for efficiency’s sake.
If you need a &str
instead of a BumpBox<str>
, consider
str::from_utf8
.
The inverse of this method is into_boxed_bytes
.
§Errors
Returns Err
if the slice is not UTF-8 with a description as to why the
provided bytes are not UTF-8. The vector you moved in is also included.
§Examples
Basic usage:
// some bytes, in a vector
let sparkle_heart = bump.alloc_slice_copy(&[240, 159, 146, 150]);
// We know these bytes are valid, so we'll use `unwrap()`.
let sparkle_heart = BumpBox::from_utf8(sparkle_heart).unwrap();
assert_eq!(sparkle_heart, "💖");
Incorrect bytes:
// some invalid bytes, in a vector
let sparkle_heart = bump.alloc_slice_copy(&[0, 159, 146, 150]);
assert!(BumpBox::from_utf8(sparkle_heart).is_err());
Sourcepub const unsafe fn from_utf8_unchecked(bytes: BumpBox<'a, [u8]>) -> Self
pub const unsafe fn from_utf8_unchecked(bytes: BumpBox<'a, [u8]>) -> Self
Converts a vector of bytes to a BumpString
without checking that the
string contains valid UTF-8.
See the safe version, from_utf8
, for more details.
§Safety
The bytes passed in must be valid UTF-8.
§Examples
// some bytes, in a vector
let sparkle_heart = bump.alloc_slice_copy(&[240, 159, 146, 150]);
let sparkle_heart = unsafe {
BumpBox::from_utf8_unchecked(sparkle_heart)
};
assert_eq!(sparkle_heart, "💖");
Sourcepub fn into_boxed_bytes(self) -> BumpBox<'a, [u8]> ⓘ
pub fn into_boxed_bytes(self) -> BumpBox<'a, [u8]> ⓘ
Converts a BumpBox<str>
into a BumpBox<[u8]>
.
Sourcepub unsafe fn as_mut_bytes(&mut self) -> &mut BumpBox<'a, [u8]> ⓘ
pub unsafe fn as_mut_bytes(&mut self) -> &mut BumpBox<'a, [u8]> ⓘ
Returns a mutable reference to the bytes of this string.
§Safety
This function is unsafe because the returned &mut BumpBox<[u8]>
allows writing
bytes which are not valid UTF-8. If this constraint is violated, using
the original BumpBox<str>
after dropping the &mut BumpBox<[u8]>
may violate memory
safety, as BumpBox<str>
s must be valid UTF-8.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of bytes in the string, also referred to as its ‘length’.
Sourcepub fn split_off(&mut self, range: impl RangeBounds<usize>) -> Self
pub fn split_off(&mut self, range: impl RangeBounds<usize>) -> Self
Splits the string into two by removing the specified range.
This method does not allocate and does not change the order of the elements.
§Panics
Panics if the starting point or end point do not lie on a char
boundary, or if they’re out of bounds.
§Complexity
This operation takes O(1)
time if either the range starts at 0, ends at len
, or is empty.
Otherwise it takes O(min(end, len - start))
time.
§Examples
let mut string = bump.alloc_str("foobarbazqux");
let foo = string.split_off(..3);
assert_eq!(foo, "foo");
assert_eq!(string, "barbazqux");
let qux = string.split_off(6..);
assert_eq!(qux, "qux");
assert_eq!(string, "barbaz");
let rb = string.split_off(2..4);
assert_eq!(rb, "rb");
assert_eq!(string, "baaz");
let rest = string.split_off(..);
assert_eq!(rest, "baaz");
assert_eq!(string, "");
Sourcepub fn truncate(&mut self, new_len: usize)
pub fn truncate(&mut self, new_len: usize)
Shortens this string to the specified length.
If new_len
is greater than or equal to the string’s current length, this has no
effect.
Note that this method has no effect on the allocated capacity of the string
§Panics
Panics if new_len
does not lie on a char
boundary.
§Examples
let mut s = bump.alloc_str("hello");
s.truncate(2);
assert_eq!(s, "he");
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Truncates this string, removing all contents.
§Examples
let mut str = bump.alloc_str("hello");
str.clear();
assert!(str.is_empty());
Sourcepub fn as_ptr(&self) -> *const u8
pub fn as_ptr(&self) -> *const u8
Returns a raw pointer to the str, or a dangling raw pointer valid for zero sized reads.
Sourcepub fn as_mut_ptr(&mut self) -> *mut u8
pub fn as_mut_ptr(&mut self) -> *mut u8
Returns an unsafe mutable pointer to str, or a dangling raw pointer valid for zero sized reads.
Sourcepub const fn as_non_null(&self) -> NonNull<u8>
pub const fn as_non_null(&self) -> NonNull<u8>
Returns a NonNull
pointer to the string’s buffer, or a dangling
NonNull
pointer valid for zero sized reads if the vector didn’t allocate.
The caller must ensure that the string outlives the pointer this function returns, or else it will end up dangling. Modifying the string may cause its buffer to be reallocated, which would also make any pointers to it invalid.
This method guarantees that for the purpose of the aliasing model, this method
does not materialize a reference to the underlying slice, and thus the returned pointer
will remain valid when mixed with other calls to as_ptr
, as_mut_ptr
,
and as_non_null
.
Note that calling other methods that materialize references to the slice,
or references to specific elements you are planning on accessing through this pointer,
may still invalidate this pointer.
See the example below for how this guarantee can be used.
§Examples
Due to the aliasing guarantee, the following code is legal:
unsafe {
let v = bump.alloc_str("a");
let ptr1 = v.as_non_null();
ptr1.write(b'b');
let ptr2 = v.as_non_null();
ptr2.write(b'c');
// Notably, the write to `ptr2` did *not* invalidate `ptr1`:
ptr1.write(b'd');
}
Sourcepub unsafe fn set_len(&mut self, new_len: usize)
pub unsafe fn set_len(&mut self, new_len: usize)
Forces the length of the string to new_len
.
This is a low-level operation that maintains none of the normal
invariants of the type. Normally changing the length of a boxed slice
is done using one of the safe operations instead, such as
truncate
or clear
.
§Safety
new_len
must be less than or equal to thecapacity
(capacity is not tracked by this type).new_len
must lie on achar
boundary- The elements at
old_len..new_len
must be initialized.
Sourcepub fn remove(&mut self, idx: usize) -> char
pub fn remove(&mut self, idx: usize) -> char
Removes a char
from this string at a byte position and returns it.
This is an O(n) operation, as it requires copying every element in the buffer.
§Panics
Panics if idx
is larger than or equal to the string’s length,
or if it does not lie on a char
boundary.
§Examples
let mut s = bump.alloc_str("abç");
assert_eq!(s.remove(0), 'a');
assert_eq!(s.remove(1), 'ç');
assert_eq!(s.remove(0), 'b');
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the characters specified by the predicate.
In other words, remove all characters c
such that f(c)
returns false
.
This method operates in place, visiting each character exactly once in the
original order, and preserves the order of the retained characters.
§Examples
let mut s = bump.alloc_str("f_o_ob_ar");
s.retain(|c| c != '_');
assert_eq!(s, "foobar");
Because the elements are visited exactly once in the original order, external state may be used to decide which elements to keep.
let mut s = bump.alloc_str("abcde");
let keep = [false, true, true, false, true];
let mut iter = keep.iter();
s.retain(|_| *iter.next().unwrap());
assert_eq!(s, "bce");
Sourcepub fn drain<R>(&mut self, range: R) -> Drain<'_> ⓘwhere
R: RangeBounds<usize>,
pub fn drain<R>(&mut self, range: R) -> Drain<'_> ⓘwhere
R: RangeBounds<usize>,
Removes the specified range from the string in bulk, returning all removed characters as an iterator.
The returned iterator keeps a mutable borrow on the string to optimize its implementation.
§Panics
Panics if the starting point or end point do not lie on a char
boundary, or if they’re out of bounds.
§Leaking
If the returned iterator goes out of scope without being dropped (due to
core::mem::forget
, for example), the string may still contain a copy
of any drained characters, or may have lost characters arbitrarily,
including characters outside the range.
§Examples
Basic usage:
let mut s = bump.alloc_str("α is alpha, β is beta");
let beta_offset = s.find('β').unwrap_or(s.len());
// Remove the range up until the β from the string
let t: String = s.drain(..beta_offset).collect();
assert_eq!(t, "α is alpha, ");
assert_eq!(s, "β is beta");
// A full range clears the string, like `clear()` does
s.drain(..);
assert_eq!(s, "");
Source§impl<'a, T: Sized> BumpBox<'a, MaybeUninit<T>>
impl<'a, T: Sized> BumpBox<'a, MaybeUninit<T>>
Sourcepub fn init(self, value: T) -> BumpBox<'a, T> ⓘ
pub fn init(self, value: T) -> BumpBox<'a, T> ⓘ
Initializes self
with value
.
§Examples
let uninit = bump.alloc_uninit();
let init = uninit.init(1);
assert_eq!(*init, 1);
Sourcepub unsafe fn assume_init(self) -> BumpBox<'a, T> ⓘ
pub unsafe fn assume_init(self) -> BumpBox<'a, T> ⓘ
§Safety
It is up to the caller to guarantee that the MaybeUninit<T>
really is in an initialized state. Calling this when the content is not yet fully initialized causes immediate undefined behavior.
Source§impl<'a, T: Sized> BumpBox<'a, [MaybeUninit<T>]>
impl<'a, T: Sized> BumpBox<'a, [MaybeUninit<T>]>
Sourcepub fn init_fill(self, value: T) -> BumpBox<'a, [T]> ⓘwhere
T: Clone,
pub fn init_fill(self, value: T) -> BumpBox<'a, [T]> ⓘwhere
T: Clone,
Initializes self
by filling it with elements by cloning value
.
§Examples
let uninit = bump.alloc_uninit_slice(10);
let init = uninit.init_fill(1);
assert_eq!(init, [1; 10]);
Sourcepub fn init_fill_with(self, f: impl FnMut() -> T) -> BumpBox<'a, [T]> ⓘ
pub fn init_fill_with(self, f: impl FnMut() -> T) -> BumpBox<'a, [T]> ⓘ
Initializes self
by filling it with elements returned by calling a closure repeatedly.
This method uses a closure to create new values. If you’d rather
Clone
a given value, use init_fill
. If you want to use the Default
trait to generate values, you can pass Default::default
as the
argument.
§Examples
let uninit = bump.alloc_uninit_slice(10);
let init = uninit.init_fill_with(Default::default);
assert_eq!(init, [0; 10]);
Sourcepub fn init_fill_iter(self, iter: impl Iterator<Item = T>) -> BumpBox<'a, [T]> ⓘ
pub fn init_fill_iter(self, iter: impl Iterator<Item = T>) -> BumpBox<'a, [T]> ⓘ
Initializes self
by filling it with elements returned from an iterator.
§Panics
This function will panic if the iterator runs out of items before the slice is filled.
§Examples
let uninit = bump.alloc_uninit_slice(5);
let init = uninit.init_fill_iter(['a', 'b'].iter().copied().cycle());
assert_eq!(init, ['a', 'b', 'a', 'b', 'a']);
Sourcepub fn init_copy(self, slice: &[T]) -> BumpBox<'a, [T]> ⓘwhere
T: Copy,
pub fn init_copy(self, slice: &[T]) -> BumpBox<'a, [T]> ⓘwhere
T: Copy,
Initializes self
by copying the elements from slice
into self
.
The length of slice
must be the same as self
.
§Panics
This function will panic if the two slices have different lengths.
Sourcepub fn init_clone(self, slice: &[T]) -> BumpBox<'a, [T]> ⓘwhere
T: Clone,
pub fn init_clone(self, slice: &[T]) -> BumpBox<'a, [T]> ⓘwhere
T: Clone,
Initializes self
by cloning the elements from slice
into self
.
The length of slice
must be the same as self
.
§Panics
This function will panic if the two slices have different lengths.
Source§impl<'a, T> BumpBox<'a, [T]>
impl<'a, T> BumpBox<'a, [T]>
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of elements in the slice, also referred to as its ‘length’.
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes the last element from a slice and returns it, or None
if it
is empty.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the slice, removing all values.
§Examples
let mut slice = bump.alloc_slice_copy(&[1, 2, 3]);
slice.clear();
assert!(slice.is_empty());
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Shortens the slice, keeping the first len
elements and dropping
the rest.
If len
is greater than the slice’s current length, this has no
effect.
The drain
method can emulate truncate
, but causes the excess
elements to be returned instead of dropped.
Note that this method has no effect on the allocated capacity of the vector.
§Examples
Truncating a five element vector to two elements:
let mut slice = bump.alloc_slice_copy(&[1, 2, 3, 4, 5]);
slice.truncate(2);
assert_eq!(slice, [1, 2]);
No truncation occurs when len
is greater than the slice’s current
length:
let mut slice = bump.alloc_slice_copy(&[1, 2, 3]);
slice.truncate(8);
assert_eq!(slice, [1, 2, 3]);
Truncating when len == 0
is equivalent to calling the clear
method.
let mut slice = bump.alloc_slice_copy(&[1, 2, 3]);
slice.truncate(0);
assert_eq!(slice, []);
Sourcepub const fn as_slice(&self) -> &[T]
pub const fn as_slice(&self) -> &[T]
Extracts a slice containing the entire boxed slice.
Equivalent to &s[..]
.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Extracts a mutable slice containing the entire boxed slice.
Equivalent to &mut s[..]
.
Sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Returns a raw pointer to the slice, or a dangling raw pointer valid for zero sized reads.
Sourcepub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_mut_ptr(&mut self) -> *mut T
Returns an unsafe mutable pointer to slice, or a dangling raw pointer valid for zero sized reads.
Sourcepub const fn as_non_null(&self) -> NonNull<T>
pub const fn as_non_null(&self) -> NonNull<T>
Returns a NonNull
pointer to the vector’s buffer, or a dangling
NonNull
pointer valid for zero sized reads if the vector didn’t allocate.
The caller must ensure that the vector outlives the pointer this function returns, or else it will end up dangling. Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.
This method guarantees that for the purpose of the aliasing model, this method
does not materialize a reference to the underlying slice, and thus the returned pointer
will remain valid when mixed with other calls to as_ptr
, as_mut_ptr
,
and as_non_null
.
Note that calling other methods that materialize references to the slice,
or references to specific elements you are planning on accessing through this pointer,
may still invalidate this pointer.
See the example below for how this guarantee can be used.
§Examples
Due to the aliasing guarantee, the following code is legal:
unsafe {
let mut v = bump.alloc_slice_copy(&[0]);
let ptr1 = v.as_non_null();
ptr1.write(1);
let ptr2 = v.as_non_null();
ptr2.write(2);
// Notably, the write to `ptr2` did *not* invalidate `ptr1`:
ptr1.write(3);
}
Sourcepub unsafe fn set_len(&mut self, new_len: usize)
pub unsafe fn set_len(&mut self, new_len: usize)
Forces the length of the slice to new_len
.
This is a low-level operation that maintains none of the normal
invariants of the type. Normally changing the length of a boxed slice
is done using one of the safe operations instead, such as
truncate
or clear
.
§Safety
new_len
must be less than or equal to thecapacity
(capacity is not tracked by this type).- The elements at
old_len..new_len
must be initialized.
Sourcepub fn remove(&mut self, index: usize) -> T
pub fn remove(&mut self, index: usize) -> T
Removes and returns the element at position index
within the vector,
shifting all elements after it to the left.
Note: Because this shifts over the remaining elements, it has a
worst-case performance of O(n). If you don’t need the order of elements
to be preserved, use swap_remove
instead.
§Panics
Panics if index
is out of bounds.
§Examples
let mut v = bump.alloc_slice_copy(&[1, 2, 3]);
assert_eq!(v.remove(1), 2);
assert_eq!(v, [1, 3]);
Sourcepub fn swap_remove(&mut self, index: usize) -> T
pub fn swap_remove(&mut self, index: usize) -> T
Removes an element from the vector and returns it.
The removed element is replaced by the last element of the vector.
This does not preserve ordering, but is O(1).
If you need to preserve the element order, use remove
instead.
§Panics
Panics if index
is out of bounds.
§Examples
let mut v = bump.alloc_slice_copy(&["foo", "bar", "baz", "qux"]);
assert_eq!(v.swap_remove(1), "bar");
assert_eq!(v, ["foo", "qux", "baz"]);
assert_eq!(v.swap_remove(0), "foo");
assert_eq!(v, ["baz", "qux"]);
Sourcepub fn split_off(&mut self, range: impl RangeBounds<usize>) -> Self
pub fn split_off(&mut self, range: impl RangeBounds<usize>) -> Self
Splits the vector into two by removing the specified range.
This method does not allocate and does not change the order of the elements.
§Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.
§Complexity
This operation takes O(1)
time if either the range starts at 0, ends at len
, or is empty.
Otherwise it takes O(min(end, len - start))
time.
§Examples
let mut slice = bump.alloc_slice_copy(&[1, 2, 3, 4, 5, 6, 7, 8]);
let front = slice.split_off(..2);
assert_eq!(front, [1, 2]);
assert_eq!(slice, [3, 4, 5, 6, 7, 8]);
let back = slice.split_off(4..);
assert_eq!(back, [7, 8]);
assert_eq!(slice, [3, 4, 5, 6]);
let middle = slice.split_off(1..3);
assert_eq!(middle, [4, 5]);
assert_eq!(slice, [3, 6]);
let rest = slice.split_off(..);
assert_eq!(rest, [3, 6]);
assert_eq!(slice, []);
Sourcepub fn split_at(self, at: usize) -> (Self, Self)
pub fn split_at(self, at: usize) -> (Self, Self)
Divides one slice into two at an index.
The first will contain all indices from [0, mid)
(excluding
the index mid
itself) and the second will contain all
indices from [mid, len)
(excluding the index len
itself).
§Panics
Panics if mid > len
.
§Examples
let v = bump.alloc_slice_copy(&[1, 2, 3, 4, 5, 6]);
{
let (left, right) = v.split_at(0);
assert_eq!(left, []);
assert_eq!(right, [1, 2, 3, 4, 5, 6]);
}
let v = bump.alloc_slice_copy(&[1, 2, 3, 4, 5, 6]);
{
let (left, right) = v.split_at(2);
assert_eq!(left, [1, 2]);
assert_eq!(right, [3, 4, 5, 6]);
}
let v = bump.alloc_slice_copy(&[1, 2, 3, 4, 5, 6]);
{
let (left, right) = v.split_at(6);
assert_eq!(left, [1, 2, 3, 4, 5, 6]);
assert_eq!(right, []);
}
Sourcepub unsafe fn split_at_unchecked(self, mid: usize) -> (Self, Self)
pub unsafe fn split_at_unchecked(self, mid: usize) -> (Self, Self)
Divides one slice into two at an index, without doing bounds checking.
The first will contain all indices from [0, mid)
(excluding
the index mid
itself) and the second will contain all
indices from [mid, len)
(excluding the index len
itself).
For a safe alternative see split_at
.
§Safety
Calling this method with an out-of-bounds index is undefined behavior
even if the resulting reference is not used. The caller has to ensure that
0 <= mid <= self.len()
.
§Examples
let v = bump.alloc_slice_copy(&[1, 2, 3, 4, 5, 6]);
unsafe {
let (left, right) = v.split_at_unchecked(0);
assert_eq!(left, []);
assert_eq!(right, [1, 2, 3, 4, 5, 6]);
}
let v = bump.alloc_slice_copy(&[1, 2, 3, 4, 5, 6]);
unsafe {
let (left, right) = v.split_at_unchecked(2);
assert_eq!(left, [1, 2]);
assert_eq!(right, [3, 4, 5, 6]);
}
let v = bump.alloc_slice_copy(&[1, 2, 3, 4, 5, 6]);
unsafe {
let (left, right) = v.split_at_unchecked(6);
assert_eq!(left, [1, 2, 3, 4, 5, 6]);
assert_eq!(right, []);
}
Sourcepub fn split_first(self) -> Option<(BumpBox<'a, T>, BumpBox<'a, [T]>)>
pub fn split_first(self) -> Option<(BumpBox<'a, T>, BumpBox<'a, [T]>)>
Returns the first and all the rest of the elements of the slice, or None
if it is empty.
This does consume the BumpBox
. You can create a new empty one with BumpBox::default
.
§Examples
let x = bump.alloc_slice_copy(&[0, 1, 2]);
if let Some((first, elements)) = x.split_first() {
assert_eq!(&*first, &0);
assert_eq!(&*elements, &[1, 2]);
}
Sourcepub fn split_last(self) -> Option<(BumpBox<'a, T>, BumpBox<'a, [T]>)>
pub fn split_last(self) -> Option<(BumpBox<'a, T>, BumpBox<'a, [T]>)>
Returns the last and all the rest of the elements of the slice, or None
if it is empty.
This does consume the BumpBox
. You can create a new empty one with BumpBox::default
.
§Examples
let x = bump.alloc_slice_copy(&[0, 1, 2]);
if let Some((last, elements)) = x.split_last() {
assert_eq!(&*last, &2);
assert_eq!(&*elements, &[0, 1]);
}
Sourcepub fn merge(self, other: Self) -> Self
pub fn merge(self, other: Self) -> Self
Merges two contiguous slices into one.
§Panics
Panics if self
and other
are not contiguous.
Panics if T
is a zero-sized type and adding the lengths overflows.
§Examples
Split and merge back together.
let v = bump.alloc_slice_copy(&[1, 2, 3, 4, 5, 6]);
let (left, right) = v.split_at(3);
assert_eq!(left, [1, 2, 3]);
assert_eq!(right, [4, 5, 6]);
let merged = left.merge(right);
assert_eq!(merged, [1, 2, 3, 4, 5, 6]);
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate, passing a mutable reference to it.
In other words, remove all elements e
such that f(&mut e)
returns false
.
This method operates in place, visiting each element exactly once in the
original order, and preserves the order of the retained elements.
§Examples
let mut slice = bump.alloc_slice_copy(&[1, 2, 3, 4]);
slice.retain(|x| if *x <= 3 {
*x += 1;
true
} else {
false
});
assert_eq!(slice, [2, 3, 4]);
Sourcepub fn drain<R>(&mut self, range: R) -> Drain<'_, T> ⓘwhere
R: RangeBounds<usize>,
pub fn drain<R>(&mut self, range: R) -> Drain<'_, T> ⓘwhere
R: RangeBounds<usize>,
Removes the specified range from the slice in bulk, returning all removed elements as an iterator. If the iterator is dropped before being fully consumed, it drops the remaining removed elements.
The returned iterator keeps a mutable borrow on the slice to optimize its implementation.
§Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.
§Leaking
If the returned iterator goes out of scope without being dropped (due to
mem::forget
, for example), the vector may have lost and leaked
elements arbitrarily, including elements outside the range.
§Examples
let mut v = bump.alloc_slice_copy(&[1, 2, 3]);
let u = bump.alloc_iter(v.drain(1..));
assert_eq!(v, [1]);
assert_eq!(u, [2, 3]);
// A full range clears the slice, like `clear()` does
v.drain(..);
assert_eq!(v, []);
Sourcepub fn extract_if<F>(&mut self, filter: F) -> ExtractIf<'_, T, F> ⓘ
pub fn extract_if<F>(&mut self, filter: F) -> ExtractIf<'_, T, F> ⓘ
Creates an iterator which uses a closure to determine if an element should be removed.
If the closure returns true, then the element is removed and yielded. If the closure returns false, the element will remain in the slice and will not be yielded by the iterator.
If the returned ExtractIf
is not exhausted, e.g. because it is dropped without iterating
or the iteration short-circuits, then the remaining elements will be retained.
Use retain
with a negated predicate if you do not need the returned iterator.
Using this method is equivalent to the following code:
let mut i = 0;
while i < slice.len() {
if some_predicate(&mut slice[i]) {
let val = slice.remove(i);
// your code here
} else {
i += 1;
}
}
But extract_if
is easier to use. extract_if
is also more efficient,
because it can backshift the elements of the array in bulk.
Note that extract_if
also lets you mutate every element in the filter closure,
regardless of whether you choose to keep or remove it.
§Examples
Splitting an array into evens and odds, reusing the original allocation:
let mut numbers = bump.alloc_slice_copy(&[1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15]);
let evens = bump.alloc_iter(numbers.extract_if(|x| *x % 2 == 0));
let odds = numbers;
assert_eq!(evens, [2, 4, 6, 8, 14]);
assert_eq!(odds, [1, 3, 5, 9, 11, 13, 15]);
Sourcepub fn dedup_by_key<F, K>(&mut self, key: F)
pub fn dedup_by_key<F, K>(&mut self, key: F)
Removes all but the first of consecutive elements in the slice that resolve to the same key.
If the slice is sorted, this removes all duplicates.
§Examples
let mut slice = bump.alloc_slice_copy(&[10, 20, 21, 30, 20]);
slice.dedup_by_key(|i| *i / 10);
assert_eq!(slice, [10, 20, 30, 20]);
Sourcepub fn dedup_by<F>(&mut self, same_bucket: F)
pub fn dedup_by<F>(&mut self, same_bucket: F)
Removes all but the first of consecutive elements in the vector satisfying a given equality relation.
The same_bucket
function is passed references to two elements from the vector and
must determine if the elements compare equal. The elements are passed in opposite order
from their order in the slice, so if same_bucket(a, b)
returns true
, a
is removed.
If the vector is sorted, this removes all duplicates.
§Examples
let mut slice = bump.alloc_slice_copy(&["foo", "bar", "Bar", "baz", "bar"]);
slice.dedup_by(|a, b| a.eq_ignore_ascii_case(b));
assert_eq!(slice, ["foo", "bar", "baz", "bar"]);
Sourcepub fn partition<F>(self, f: F) -> (Self, Self)
pub fn partition<F>(self, f: F) -> (Self, Self)
Consumes self
, creating two boxed slices from it.
The predicate passed to partition()
can return true
, or false
.
partition()
returns a pair, all of the elements for which it returned
true
, and all of the elements for which it returned false
.
See also is_partitioned()
and partition_in_place()
.
§Examples
Basic usage:
let slice = bump.alloc_slice_copy(&[1, 2, 3, 4, 5, 6, 7]);
let (even, odd) = slice.partition(|n| n % 2 == 0);
assert!(even.iter().all(|n| n % 2 == 0));
assert!(odd.iter().all(|n| n % 2 != 0));
Sourcepub fn map_in_place<U>(self, f: impl FnMut(T) -> U) -> BumpBox<'a, [U]> ⓘ
pub fn map_in_place<U>(self, f: impl FnMut(T) -> U) -> BumpBox<'a, [U]> ⓘ
Returns a boxed slice of the same size as self
, with function f
applied to each element in order.
This function only compiles when U
s size and alignment is less or equal to T
’s or if U
has a size of 0.
§Examples
Mapping to a type with an equal alignment and size:
let a = bump.alloc_slice_copy(&[0, 1, 2]);
let b = a.map_in_place(NonZero::new);
assert_eq!(format!("{b:?}"), "[None, Some(1), Some(2)]");
Mapping to a type with a smaller alignment and size:
let a: BumpBox<[u32]> = bump.alloc_slice_copy(&[0, 1, 2]);
let b: BumpBox<[u16]> = a.map_in_place(|i| i as u16);
assert_eq!(b, [0, 1, 2]);
Mapping to a type with a greater alignment won’t compile:
let a: BumpBox<[[u8; 4]]> = bump.alloc_slice_copy(&[[0, 1, 2, 3]]);
let b: BumpBox<[u32]> = a.map_in_place(u32::from_le_bytes);
Mapping to a type with a greater size won’t compile:
let a: BumpBox<[u32]> = bump.alloc_slice_copy(&[42]);
let b: BumpBox<[[u32; 2]]> = a.map_in_place(|i| [i; 2]);
Source§impl<'a, T, const N: usize> BumpBox<'a, [[T; N]]>
impl<'a, T, const N: usize> BumpBox<'a, [[T; N]]>
Sourcepub fn into_flattened(self) -> BumpBox<'a, [T]> ⓘ
pub fn into_flattened(self) -> BumpBox<'a, [T]> ⓘ
Takes a BumpBox<[[T; N]]>
and flattens it into a BumpBox<[T]>
.
§Panics
Panics if the length of the resulting slice would overflow a usize
.
This is only possible when flattening a slice of arrays of zero-sized
types, and thus tends to be irrelevant in practice. If
size_of::<T>() > 0
, this will never panic.
§Examples
let mut slice = bump.alloc_slice_copy(&[[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
assert_eq!(slice.pop(), Some([7, 8, 9]));
let mut flattened = slice.into_flattened();
assert_eq!(flattened.pop(), Some(6));
Source§impl<'a> BumpBox<'a, dyn Any>
impl<'a> BumpBox<'a, dyn Any>
Source§impl<'a> BumpBox<'a, dyn Any + Send>
impl<'a> BumpBox<'a, dyn Any + Send>
Trait Implementations§
Source§impl<T: ?Sized> BorrowMut<T> for BumpBox<'_, T>
impl<T: ?Sized> BorrowMut<T> for BumpBox<'_, T>
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T: ?Sized + BufRead> BufRead for BumpBox<'_, T>
Available on crate feature std
only.
impl<T: ?Sized + BufRead> BufRead for BumpBox<'_, T>
std
only.Source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
Read
methods, if empty. Read moreSource§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amount
of additional bytes from the internal buffer as having been read.
Subsequent calls to read
only return bytes that have not been marked as read. Read moreSource§fn read_line(&mut self, buf: &mut String) -> Result<usize>
fn read_line(&mut self, buf: &mut String) -> Result<usize>
0xA
byte) is reached, and append
them to the provided String
buffer. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left
)read
. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
byte
or EOF is reached. Read moreSource§impl<T: ?Sized> Drop for BumpBox<'_, T>
Available on crate feature nightly-dropck-eyepatch
only.
impl<T: ?Sized> Drop for BumpBox<'_, T>
nightly-dropck-eyepatch
only.Source§impl<'a> Extend<BumpBox<'a, str>> for String
Available on crate feature alloc
only.
impl<'a> Extend<BumpBox<'a, str>> for String
alloc
only.Source§fn extend<T: IntoIterator<Item = BumpBox<'a, str>>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = BumpBox<'a, str>>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<Args: Tuple, F: Fn<Args> + ?Sized> Fn<Args> for BumpBox<'_, F>
Available on crate feature nightly-fn-traits
only.
impl<Args: Tuple, F: Fn<Args> + ?Sized> Fn<Args> for BumpBox<'_, F>
nightly-fn-traits
only.Source§impl<Args: Tuple, F: FnMut<Args> + ?Sized> FnMut<Args> for BumpBox<'_, F>
Available on crate feature nightly-fn-traits
only.
impl<Args: Tuple, F: FnMut<Args> + ?Sized> FnMut<Args> for BumpBox<'_, F>
nightly-fn-traits
only.Source§impl<Args: Tuple, F: FnOnce<Args> + ?Sized> FnOnce<Args> for BumpBox<'_, F>
Available on crate feature nightly-fn-traits
only.
impl<Args: Tuple, F: FnOnce<Args> + ?Sized> FnOnce<Args> for BumpBox<'_, F>
nightly-fn-traits
only.Source§impl<T: ?Sized + Hasher> Hasher for BumpBox<'_, T>
impl<T: ?Sized + Hasher> Hasher for BumpBox<'_, T>
Source§fn write_u128(&mut self, i: u128)
fn write_u128(&mut self, i: u128)
u128
into this hasher.Source§fn write_usize(&mut self, i: usize)
fn write_usize(&mut self, i: usize)
usize
into this hasher.Source§fn write_i128(&mut self, i: i128)
fn write_i128(&mut self, i: i128)
i128
into this hasher.Source§fn write_isize(&mut self, i: isize)
fn write_isize(&mut self, i: isize)
isize
into this hasher.Source§fn write_length_prefix(&mut self, len: usize)
fn write_length_prefix(&mut self, len: usize)
hasher_prefixfree_extras
)Source§impl<'a, T: Zeroable> InitZeroed<'a> for BumpBox<'a, [MaybeUninit<T>]>
Available on crate feature bytemuck
only.
impl<'a, T: Zeroable> InitZeroed<'a> for BumpBox<'a, [MaybeUninit<T>]>
bytemuck
only.Source§impl<'a, T: FromZeros> InitZeroed<'a> for BumpBox<'a, [MaybeUninit<T>]>
Available on crate feature zerocopy-08
only.
impl<'a, T: FromZeros> InitZeroed<'a> for BumpBox<'a, [MaybeUninit<T>]>
zerocopy-08
only.Source§impl<'a, T: Zeroable> InitZeroed<'a> for BumpBox<'a, MaybeUninit<T>>
Available on crate feature bytemuck
only.
impl<'a, T: Zeroable> InitZeroed<'a> for BumpBox<'a, MaybeUninit<T>>
bytemuck
only.Source§impl<'a, T: FromZeros> InitZeroed<'a> for BumpBox<'a, MaybeUninit<T>>
Available on crate feature zerocopy-08
only.
impl<'a, T: FromZeros> InitZeroed<'a> for BumpBox<'a, MaybeUninit<T>>
zerocopy-08
only.Source§impl<'b, T> IntoIterator for &'b BumpBox<'_, [T]>
impl<'b, T> IntoIterator for &'b BumpBox<'_, [T]>
Source§impl<'b, T> IntoIterator for &'b mut BumpBox<'_, [T]>
impl<'b, T> IntoIterator for &'b mut BumpBox<'_, [T]>
Source§impl<'a, T> IntoIterator for BumpBox<'a, [T]>
impl<'a, T> IntoIterator for BumpBox<'a, [T]>
Source§impl<'a, T: ?Sized + Ord> Ord for BumpBox<'a, T>
impl<'a, T: ?Sized + Ord> Ord for BumpBox<'a, T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'b, T: ?Sized + PartialOrd> PartialOrd<BumpBox<'b, T>> for BumpBox<'_, T>
impl<'b, T: ?Sized + PartialOrd> PartialOrd<BumpBox<'b, T>> for BumpBox<'_, T>
Source§impl<T: ?Sized + Read> Read for BumpBox<'_, T>
Available on crate feature std
only.
impl<T: ?Sized + Read> Read for BumpBox<'_, T>
std
only.Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read
, except that it reads into a slice of buffers. Read moreSource§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf
. Read moreSource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf
. Read moreSource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)Source§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl<T: ?Sized + Seek> Seek for BumpBox<'_, T>
Available on crate feature std
only.
impl<T: ?Sized + Seek> Seek for BumpBox<'_, T>
std
only.Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
Source§fn stream_position(&mut self) -> Result<u64>
fn stream_position(&mut self) -> Result<u64>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§impl<T: Serialize + ?Sized> Serialize for BumpBox<'_, T>
Available on crate feature serde
only.
impl<T: Serialize + ?Sized> Serialize for BumpBox<'_, T>
serde
only.Source§impl<T> TakeOwnedSlice for BumpBox<'_, [T]>
impl<T> TakeOwnedSlice for BumpBox<'_, [T]>
Source§impl<T: ?Sized + Write> Write for BumpBox<'_, T>
Available on crate feature std
only.
impl<T: ?Sized + Write> Write for BumpBox<'_, T>
std
only.Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Source§fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)impl<'a, T, U> CoerceUnsized<BumpBox<'a, U>> for BumpBox<'a, T>
nightly-coerce-unsized
only.impl<T: ?Sized + Eq> Eq for BumpBox<'_, T>
impl<T> NoDrop for BumpBox<'_, T>where
T: NoDrop,
impl<T: ?Sized + Send> Send for BumpBox<'_, T>
impl<T: ?Sized + Sync> Sync for BumpBox<'_, T>
impl<T: ?Sized> Unpin for BumpBox<'_, T>
Auto Trait Implementations§
impl<'a, T> Freeze for BumpBox<'a, T>where
T: ?Sized,
impl<'a, T> RefUnwindSafe for BumpBox<'a, T>where
T: RefUnwindSafe + ?Sized,
impl<'a, T> UnwindSafe for BumpBox<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> OwnedSlice for Twhere
T: TakeOwnedSlice,
impl<T> OwnedSlice for Twhere
T: TakeOwnedSlice,
Source§type Item = <T as TakeOwnedSlice>::Item
type Item = <T as TakeOwnedSlice>::Item
Source§fn into_take_owned_slice(self) -> <T as OwnedSlice>::Take
fn into_take_owned_slice(self) -> <T as OwnedSlice>::Take
TakeOwnedSlice
.Source§impl<F> Pattern for F
impl<F> Pattern for F
Source§type Searcher<'a> = CharPredicateSearcher<'a, F>
type Searcher<'a> = CharPredicateSearcher<'a, F>
pattern
)Source§fn into_searcher<'a>(self, haystack: &'a str) -> CharPredicateSearcher<'a, F>
fn into_searcher<'a>(self, haystack: &'a str) -> CharPredicateSearcher<'a, F>
pattern
)self
and the haystack
to search in.Source§fn is_contained_in<'a>(self, haystack: &'a str) -> bool
fn is_contained_in<'a>(self, haystack: &'a str) -> bool
pattern
)Source§fn is_prefix_of<'a>(self, haystack: &'a str) -> bool
fn is_prefix_of<'a>(self, haystack: &'a str) -> bool
pattern
)Source§fn strip_prefix_of<'a>(self, haystack: &'a str) -> Option<&'a str>
fn strip_prefix_of<'a>(self, haystack: &'a str) -> Option<&'a str>
pattern
)Source§fn is_suffix_of<'a>(self, haystack: &'a str) -> boolwhere
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
fn is_suffix_of<'a>(self, haystack: &'a str) -> boolwhere
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
pattern
)Source§fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&'a str>where
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&'a str>where
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
pattern
)Source§fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>>
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>>
pattern
)