Struct BumpBox

Source
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

§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 + NoDrop> BumpBox<'a, T>

Source

pub fn into_ref(self) -> &'a T

Turns this BumpBox<T> into &T that is live for this bump scope. This is only available for NoDrop types so you don’t omit dropping a value for which it matters.

!NoDrop types can still be turned into references via leak.

Source

pub fn into_mut(self) -> &'a mut T

Turns this BumpBox<T> into &mut T that is live for this bump scope. This is only available for NoDrop types so you don’t omit dropping a value for which it matters.

!NoDrop types can still be turned into references via leak.

Source§

impl<'a, T: ?Sized> BumpBox<'a, T>

Source

pub fn into_box<A, B>(self, allocator: A) -> B
where 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);
Source

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);
Source

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);
}
Source

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() }
Source

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>

Source

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);
Source

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>

Source

pub const EMPTY_STR: Self

Empty str.

Source

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());
Source

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, "💖");
Source

pub fn into_boxed_bytes(self) -> BumpBox<'a, [u8]>

Converts a BumpBox<str> into a BumpBox<[u8]>.

Source

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.

Source

pub const fn len(&self) -> usize

Returns the number of bytes in the string, also referred to as its ‘length’.

Source

pub const fn is_empty(&self) -> bool

Returns true if the slice contains no elements.

Source

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, "");
Source

pub fn pop(&mut self) -> Option<char>

Removes the last character from the string buffer and returns it.

Returns None if this string is empty.

§Examples
let mut s = bump.alloc_str("abč");

assert_eq!(s.pop(), Some('č'));
assert_eq!(s.pop(), Some('b'));
assert_eq!(s.pop(), Some('a'));

assert_eq!(s.pop(), None);
Source

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");
Source

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());
Source

pub fn as_ptr(&self) -> *const u8

Returns a raw pointer to the str, or a dangling raw pointer valid for zero sized reads.

Source

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.

Source

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');
}
Source

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 the capacity (capacity is not tracked by this type).
  • new_len must lie on a char boundary
  • The elements at old_len..new_len must be initialized.
Source

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');
Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(char) -> bool,

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");
Source

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>>

Source

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);
Source

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.

See MaybeUninit::assume_init.

Source§

impl<'a, T: Sized> BumpBox<'a, [MaybeUninit<T>]>

Source

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]);
Source

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]);
Source

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']);
Source

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.

Source

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

pub unsafe fn assume_init(self) -> BumpBox<'a, [T]>

§Safety

It is up to the caller to guarantee that each MaybeUninit<T> really is in an initialized state. Calling this when the content is not yet fully initialized causes immediate undefined behavior.

See MaybeUninit::assume_init.

Source§

impl<'a, T> BumpBox<'a, [T]>

Source

pub const EMPTY: Self

Empty slice.

Source

pub const fn len(&self) -> usize

Returns the number of elements in the slice, also referred to as its ‘length’.

Source

pub const fn is_empty(&self) -> bool

Returns true if the slice contains no elements.

Source

pub fn pop(&mut self) -> Option<T>

Removes the last element from a slice and returns it, or None if it is empty.

Source

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());
Source

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, []);
Source

pub const fn as_slice(&self) -> &[T]

Extracts a slice containing the entire boxed slice.

Equivalent to &s[..].

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Extracts a mutable slice containing the entire boxed slice.

Equivalent to &mut s[..].

Source

pub fn as_ptr(&self) -> *const T

Returns a raw pointer to the slice, or a dangling raw pointer valid for zero sized reads.

Source

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.

Source

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);
}
Source

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 the capacity (capacity is not tracked by this type).
  • The elements at old_len..new_len must be initialized.
Source

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]);
Source

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"]);
Source

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, []);
Source

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, []);
}
Source

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, []);
}
Source

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]);
}
Source

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]);
}
Source

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]);
Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&mut T) -> bool,

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]);
Source

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, []);
Source

pub fn extract_if<F>(&mut self, filter: F) -> ExtractIf<'_, T, F>
where F: FnMut(&mut T) -> bool,

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]);
Source

pub fn dedup(&mut self)
where T: PartialEq,

Removes consecutive repeated elements in the slice according to the PartialEq trait implementation.

If the slice is sorted, this removes all duplicates.

§Examples
let mut slice = bump.alloc_slice_copy(&[1, 2, 2, 3, 2]);

slice.dedup();

assert_eq!(slice, [1, 2, 3, 2]);
Source

pub fn dedup_by_key<F, K>(&mut self, key: F)
where F: FnMut(&mut T) -> K, K: PartialEq,

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]);
Source

pub fn dedup_by<F>(&mut self, same_bucket: F)
where F: FnMut(&mut T, &mut T) -> bool,

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"]);
Source

pub fn partition<F>(self, f: F) -> (Self, Self)
where F: FnMut(&T) -> bool,

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));
Source

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 Us 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]]>

Source

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>

Source

pub fn downcast<T: Any>(self) -> Result<BumpBox<'a, T>, Self>

Attempt to downcast the box to a concrete type.

Source

pub unsafe fn downcast_unchecked<T: Any>(self) -> BumpBox<'a, T>

Downcasts the box to a concrete type.

For a safe alternative see downcast.

§Safety

The contained value must be of type T. Calling this method with the incorrect type is undefined behavior.

Source§

impl<'a> BumpBox<'a, dyn Any + Send>

Source

pub fn downcast<T: Any>(self) -> Result<BumpBox<'a, T>, Self>

Attempt to downcast the box to a concrete type.

Source

pub unsafe fn downcast_unchecked<T: Any>(self) -> BumpBox<'a, T>

Downcasts the box to a concrete type.

For a safe alternative see downcast.

§Safety

The contained value must be of type T. Calling this method with the incorrect type is undefined behavior.

Source§

impl<'a> BumpBox<'a, dyn Any + Send + Sync>

Source

pub fn downcast<T: Any>(self) -> Result<BumpBox<'a, T>, Self>

Attempt to downcast the box to a concrete type.

Source

pub unsafe fn downcast_unchecked<T: Any>(self) -> BumpBox<'a, T>

Downcasts the box to a concrete type.

For a safe alternative see downcast.

§Safety

The contained value must be of type T. Calling this method with the incorrect type is undefined behavior.

Trait Implementations§

Source§

impl<T: ?Sized> AsMut<T> for BumpBox<'_, T>

Source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T: ?Sized> AsRef<T> for BumpBox<'_, T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: ?Sized> Borrow<T> for BumpBox<'_, T>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T: ?Sized> BorrowMut<T> for BumpBox<'_, T>

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T: ?Sized + BufRead> BufRead for BumpBox<'_, T>

Available on crate feature std only.
Source§

fn fill_buf(&mut self) -> Result<&[u8]>

Returns the contents of the internal buffer, filling it with more data, via Read methods, if empty. Read more
Source§

fn consume(&mut self, amt: usize)

Marks the given 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 more
Source§

fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize>

Reads all bytes into buf until the delimiter byte or EOF is reached. Read more
Source§

fn read_line(&mut self, buf: &mut String) -> Result<usize>

Reads all bytes until a newline (the 0xA byte) is reached, and append them to the provided String buffer. Read more
Source§

fn has_data_left(&mut self) -> Result<bool, Error>

🔬This is a nightly-only experimental API. (buf_read_has_data_left)
Checks if there is any data left to be read. Read more
1.83.0 · Source§

fn skip_until(&mut self, byte: u8) -> Result<usize, Error>

Skips all bytes until the delimiter byte or EOF is reached. Read more
1.0.0 · Source§

fn split(self, byte: u8) -> Split<Self>
where Self: Sized,

Returns an iterator over the contents of this reader split on the byte byte. Read more
1.0.0 · Source§

fn lines(self) -> Lines<Self>
where Self: Sized,

Returns an iterator over the lines of this reader. Read more
Source§

impl<T: ?Sized + Debug> Debug for BumpBox<'_, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for BumpBox<'_, [T]>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Default for BumpBox<'_, str>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: ?Sized> Deref for BumpBox<'_, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ?Sized> DerefMut for BumpBox<'_, T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ?Sized + Display> Display for BumpBox<'_, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized> Drop for BumpBox<'_, T>

Available on crate feature nightly-dropck-eyepatch only.
Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> Extend<BumpBox<'a, str>> for String

Available on crate feature alloc only.
Source§

fn extend<T: IntoIterator<Item = BumpBox<'a, str>>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<Args: Tuple, F: Fn<Args> + ?Sized> Fn<Args> for BumpBox<'_, F>

Available on crate feature nightly-fn-traits only.
Source§

extern "rust-call" fn call(&self, args: Args) -> Self::Output

🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
Source§

impl<Args: Tuple, F: FnMut<Args> + ?Sized> FnMut<Args> for BumpBox<'_, F>

Available on crate feature nightly-fn-traits only.
Source§

extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output

🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
Source§

impl<Args: Tuple, F: FnOnce<Args> + ?Sized> FnOnce<Args> for BumpBox<'_, F>

Available on crate feature nightly-fn-traits only.
Source§

type Output = <F as FnOnce<Args>>::Output

The returned type after the call operator is used.
Source§

extern "rust-call" fn call_once(self, args: Args) -> Self::Output

🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
Source§

impl<T: ?Sized + Hash> Hash for BumpBox<'_, T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: ?Sized + Hasher> Hasher for BumpBox<'_, T>

Source§

fn finish(&self) -> u64

Returns the hash value for the values written so far. Read more
Source§

fn write(&mut self, bytes: &[u8])

Writes some data into this Hasher. Read more
Source§

fn write_u8(&mut self, i: u8)

Writes a single u8 into this hasher.
Source§

fn write_u16(&mut self, i: u16)

Writes a single u16 into this hasher.
Source§

fn write_u32(&mut self, i: u32)

Writes a single u32 into this hasher.
Source§

fn write_u64(&mut self, i: u64)

Writes a single u64 into this hasher.
Source§

fn write_u128(&mut self, i: u128)

Writes a single u128 into this hasher.
Source§

fn write_usize(&mut self, i: usize)

Writes a single usize into this hasher.
Source§

fn write_i8(&mut self, i: i8)

Writes a single i8 into this hasher.
Source§

fn write_i16(&mut self, i: i16)

Writes a single i16 into this hasher.
Source§

fn write_i32(&mut self, i: i32)

Writes a single i32 into this hasher.
Source§

fn write_i64(&mut self, i: i64)

Writes a single i64 into this hasher.
Source§

fn write_i128(&mut self, i: i128)

Writes a single i128 into this hasher.
Source§

fn write_isize(&mut self, i: isize)

Writes a single isize into this hasher.
Source§

fn write_length_prefix(&mut self, len: usize)

🔬This is a nightly-only experimental API. (hasher_prefixfree_extras)
Writes a length prefix into this hasher, as part of being prefix-free. Read more
Source§

fn write_str(&mut self, s: &str)

🔬This is a nightly-only experimental API. (hasher_prefixfree_extras)
Writes a single str into this hasher. Read more
Source§

impl<I, T: Index<I>> Index<I> for BumpBox<'_, T>

Source§

type Output = <T as Index<I>>::Output

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<I, T: IndexMut<I>> IndexMut<I> for BumpBox<'_, T>

Source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T: Zeroable> InitZeroed<'a> for BumpBox<'a, [MaybeUninit<T>]>

Available on crate feature bytemuck only.
Source§

type Output = [T]

The initialized type.
Source§

fn init_zeroed(self) -> BumpBox<'a, [T]>

Initializes self by filling it with zero. Read more
Source§

impl<'a, T: FromZeros> InitZeroed<'a> for BumpBox<'a, [MaybeUninit<T>]>

Available on crate feature zerocopy-08 only.
Source§

type Output = [T]

The initialized type.
Source§

fn init_zeroed(self) -> BumpBox<'a, [T]>

Initializes self by filling it with zero. Read more
Source§

impl<'a, T: Zeroable> InitZeroed<'a> for BumpBox<'a, MaybeUninit<T>>

Available on crate feature bytemuck only.
Source§

type Output = T

The initialized type.
Source§

fn init_zeroed(self) -> BumpBox<'a, T>

Initializes self by filling it with zero. Read more
Source§

impl<'a, T: FromZeros> InitZeroed<'a> for BumpBox<'a, MaybeUninit<T>>

Available on crate feature zerocopy-08 only.
Source§

type Output = T

The initialized type.
Source§

fn init_zeroed(self) -> BumpBox<'a, T>

Initializes self by filling it with zero. Read more
Source§

impl<'b, T> IntoIterator for &'b BumpBox<'_, [T]>

Source§

type Item = &'b T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'b, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'b, T> IntoIterator for &'b mut BumpBox<'_, [T]>

Source§

type Item = &'b mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'b, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for BumpBox<'a, [T]>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T: ?Sized + Ord> Ord for BumpBox<'a, T>

Source§

fn cmp(&self, other: &BumpBox<'a, T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a, T, const N: usize> OwnedSlice for BumpBox<'a, [T; N]>

Source§

type Item = T

The type of an element of this owned slice.
Source§

type Take = BumpBox<'a, [T]>

A type that Self can convert into that implements TakeOwnedSlice.
Source§

fn into_take_owned_slice(self) -> Self::Take

Converts this type into one that implements TakeOwnedSlice.
Source§

impl<T: ?Sized + PartialEq> PartialEq<&T> for BumpBox<'_, T>

Source§

fn eq(&self, other: &&T) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &&T) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: ?Sized + PartialEq> PartialEq<&mut T> for BumpBox<'_, T>

Source§

fn eq(&self, other: &&mut T) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &&mut T) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialEq, const N: usize> PartialEq<[T; N]> for BumpBox<'_, [T]>

Source§

fn eq(&self, other: &[T; N]) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &[T; N]) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T, U> PartialEq<BumpBox<'a, [U]>> for &[T]
where T: PartialEq<U>,

Source§

fn eq(&self, other: &BumpBox<'a, [U]>) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &BumpBox<'a, [U]>) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T, U> PartialEq<BumpBox<'a, [U]>> for &mut [T]
where T: PartialEq<U>,

Source§

fn eq(&self, other: &BumpBox<'a, [U]>) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &BumpBox<'a, [U]>) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T, U> PartialEq<BumpBox<'a, [U]>> for [T]
where T: PartialEq<U>,

Source§

fn eq(&self, other: &BumpBox<'a, [U]>) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &BumpBox<'a, [U]>) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'b, T: ?Sized + PartialEq> PartialEq<BumpBox<'b, T>> for BumpBox<'_, T>

Source§

fn eq(&self, other: &BumpBox<'b, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &BumpBox<'b, T>) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: ?Sized + PartialEq> PartialEq<T> for BumpBox<'_, T>

Source§

fn eq(&self, other: &T) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &T) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'b, T: ?Sized + PartialOrd> PartialOrd<BumpBox<'b, T>> for BumpBox<'_, T>

Source§

fn partial_cmp(&self, other: &BumpBox<'b, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
Source§

fn lt(&self, other: &BumpBox<'b, T>) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn le(&self, other: &BumpBox<'b, T>) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn ge(&self, other: &BumpBox<'b, T>) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

fn gt(&self, other: &BumpBox<'b, T>) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

impl<T: ?Sized + Read> Read for BumpBox<'_, T>

Available on crate feature std only.
Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>

Reads all bytes until EOF in this source, placing them into buf. Read more
Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize>

Reads all bytes until EOF in this source, appending them to buf. Read more
Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>

Reads the exact number of bytes required to fill buf. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
Source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

impl<T: ?Sized + Seek> Seek for BumpBox<'_, T>

Available on crate feature std only.
Source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64>

Seek to an offset, in bytes, in a stream. Read more
Source§

fn stream_position(&mut self) -> Result<u64>

Returns the current seek position from the start of the stream. Read more
1.55.0 · Source§

fn rewind(&mut self) -> Result<(), Error>

Rewind to the beginning of a stream. Read more
Source§

fn stream_len(&mut self) -> Result<u64, Error>

🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more
1.80.0 · Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Error>

Seeks relative to the current position. Read more
Source§

impl<T: Serialize + ?Sized> Serialize for BumpBox<'_, T>

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> TakeOwnedSlice for BumpBox<'_, [T]>

Source§

type Item = T

The element type of the slice.
Source§

fn owned_slice_ref(&self) -> &[Self::Item]

Returns a slice of its elements.
Source§

fn take_owned_slice(&mut self)

This will make the slice forget all of its elements. Read more
Source§

impl<T: ?Sized + Write> Write for BumpBox<'_, T>

Available on crate feature std only.
Source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Source§

fn write_all(&mut self, buf: &[u8]) -> Result<()>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>

Writes a formatted string into this writer, returning any error encountered. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more
Source§

impl<'a, T, U> CoerceUnsized<BumpBox<'a, U>> for BumpBox<'a, T>
where T: ?Sized + Unsize<U>, U: ?Sized,

Available on crate feature nightly-coerce-unsized only.
Source§

impl<T: ?Sized + Eq> Eq for BumpBox<'_, T>

Source§

impl<T> NoDrop for BumpBox<'_, T>
where T: NoDrop,

Source§

impl<T: ?Sized + Send> Send for BumpBox<'_, T>

Source§

impl<T: ?Sized + Sync> Sync for BumpBox<'_, T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OwnedSlice for T
where T: TakeOwnedSlice,

Source§

type Item = <T as TakeOwnedSlice>::Item

The type of an element of this owned slice.
Source§

type Take = T

A type that Self can convert into that implements TakeOwnedSlice.
Source§

fn into_take_owned_slice(self) -> <T as OwnedSlice>::Take

Converts this type into one that implements TakeOwnedSlice.
Source§

impl<F> Pattern for F
where F: FnMut(char) -> bool,

Source§

type Searcher<'a> = CharPredicateSearcher<'a, F>

🔬This is a nightly-only experimental API. (pattern)
Associated searcher for this pattern
Source§

fn into_searcher<'a>(self, haystack: &'a str) -> CharPredicateSearcher<'a, F>

🔬This is a nightly-only experimental API. (pattern)
Constructs the associated searcher from self and the haystack to search in.
Source§

fn is_contained_in<'a>(self, haystack: &'a str) -> bool

🔬This is a nightly-only experimental API. (pattern)
Checks whether the pattern matches anywhere in the haystack
Source§

fn is_prefix_of<'a>(self, haystack: &'a str) -> bool

🔬This is a nightly-only experimental API. (pattern)
Checks whether the pattern matches at the front of the haystack
Source§

fn strip_prefix_of<'a>(self, haystack: &'a str) -> Option<&'a str>

🔬This is a nightly-only experimental API. (pattern)
Removes the pattern from the front of haystack, if it matches.
Source§

fn is_suffix_of<'a>(self, haystack: &'a str) -> bool

🔬This is a nightly-only experimental API. (pattern)
Checks whether the pattern matches at the back of the haystack
Source§

fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&'a str>

🔬This is a nightly-only experimental API. (pattern)
Removes the pattern from the back of haystack, if it matches.
Source§

fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>>

🔬This is a nightly-only experimental API. (pattern)
Returns the pattern as utf-8 bytes if possible.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.