📝 字数:working on
std::boxed
Estimated time to read: 1 minute
pub struct Box<T, A=Global>(/*private fields*/)
where
A: Allocator,
T: ?Sized;
isize::MAX bytes.
Box vs Rc
Box provides exclusive ownership of the data on the heap.
Exclusive ownership means that a single variable has complete control over a piece of data at any given time.
Allocator
A is an optional generic parameter representing the allocator used to manage the memory. It defaults to Global which is the default global allocator provided by Rust.
Allocator is the trait bound on the A parameter.