Struct scoped_arena::Scope [−][src]
pub struct Scope<'arena, A: Allocator = Global> { /* fields omitted */ }
Expand description
Scope associated with Scope
allocator.
Allows placing values on the scope returning reference bound to scope borrow.
On drop scope drops all values placed onto it.
On drop scope frees all memory allocated from it.
Implementations
Returns new instance of arena allocator based on [Global
] allocator
with preallocated capacity in bytes.
Returns new instance of arena allocator based on provided allocator.
Returns new instance of arena allocator based on provided allocator with preallocated capacity in bytes.
Allocates a block of memory.
Returns a NonNull<u8>
meeting the size and alignment guarantees of layout.
The returned block contents should be considered uninitialized.
Returned block will be deallocated when scope is dropped.
Attempts to allocate a block of memory.
On success, returns a NonNull<u8>
meeting the size and alignment guarantees of layout.
The returned block contents should be considered uninitialized.
Returned block will be deallocated when scope is dropped.
Errors
Returning Err
indicates that memory is exhausted.
Move value onto the scope. Returns mutable reference to value with lifetime equal to scope borrow lifetime. Value on scope will be dropped when scope is dropped.
This method is as cheap as allocation if value does not needs dropping as reported by core::mem::needs_drop
.
Places value returned from function onto the scope. Returns mutable reference to value with lifetime equal to scope borrow lifetime. Value on scope will be dropped when scope is dropped.
This method is as cheap as allocation if value does not needs dropping as reported by core::mem::needs_drop
.
Tries to move value onto the scope. On success, returns mutable reference to value with lifetime equal to scope borrow lifetime. Value on scope will be dropped when scope is dropped.
This method is as cheap as allocation if value does not needs dropping as reported by core::mem::needs_drop
.
Errors
Returning Err
indicates that memory is exhausted.
Returning Err
contains original value.
pub fn try_to_scope_with<F, T>(&self, f: F) -> Result<&mut T, (AllocError, F)> where
F: FnOnce() -> T,
pub fn try_to_scope_with<F, T>(&self, f: F) -> Result<&mut T, (AllocError, F)> where
F: FnOnce() -> T,
Tries to place value return from function onto the scope. On success, returns mutable reference to value with lifetime equal to scope borrow lifetime. Value on scope will be dropped when scope is dropped.
This method is as cheap as allocation if value does not needs dropping as reported by core::mem::needs_drop
.
Errors
Returning Err
indicates that memory is exhausted.
Returning Err
contains original value.
Move values from iterator onto the scope. Returns mutable reference to slice with lifetime equal to scope borrow lifetime. Values on scope will be dropped when scope is dropped.
This method is as cheap as allocation if value does not needs dropping as reported by core::mem::needs_drop
.
This method allocates memory to hold iterator’s upper bound number of items. See core::iter::Iterator::size_hint
.
It will not consume more items.
This method will always fail for unbound iterators.
pub fn try_to_scope_from_iter<T, I>(
&self,
iter: I
) -> Result<&mut [T], (AllocError, I::IntoIter)> where
I: IntoIterator<Item = T>,
pub fn try_to_scope_from_iter<T, I>(
&self,
iter: I
) -> Result<&mut [T], (AllocError, I::IntoIter)> where
I: IntoIterator<Item = T>,
Tries to move values from iterator onto the scope. On success, returns mutable reference to slice with lifetime equal to scope borrow lifetime. Values on scope will be dropped when scope is dropped.
This method is as cheap as allocation if value does not needs dropping as reported by core::mem::needs_drop
.
This method allocates memory to hold iterator’s upper bound number of items. See core::iter::Iterator::size_hint
.
It will not consume more items.
This method will always fail for unbound iterators.
Errors
Returning Err
indicates that memory is exhausted.
Returning Err
contains original iterator.
Reports total memory allocated from underlying allocator by associated arena.
Creates scope proxy bound to the scope. Any objects allocated through proxy will be attached to the scope. Returned proxy will use reference to the underlying allocator.
Creates scope proxy bound to the scope. Any objects allocated through proxy will be attached to the scope. Returned proxy will use clone of the underlying allocator.