pub struct Box<P: Pool> { /* private fields */ }Implementations§
Source§impl<P: Pool> Box<P>
impl<P: Pool> Box<P>
Sourcepub fn new(item: P::Item) -> Option<Self>
pub fn new(item: P::Item) -> Option<Self>
Examples found in repository?
examples/simple.rs (line 11)
10fn main() {
11 let box1 = Box::<PacketPool>::new(Packet(1));
12 println!("allocated: {:?}", box1);
13
14 let box2 = Box::<PacketPool>::new(Packet(2));
15 println!("allocated: {:?}", box2);
16
17 let box3 = Box::<PacketPool>::new(Packet(3));
18 println!("allocated: {:?}", box3);
19
20 let box4 = Box::<PacketPool>::new(Packet(4));
21 println!("allocated: {:?}", box4);
22
23 let box5 = Box::<PacketPool>::new(Packet(5));
24 println!("5th allocation fails because the pool is full: {:?}", box5);
25
26 println!("dropping another allocation...");
27 mem::drop(box1);
28
29 let box5 = Box::<PacketPool>::new(Packet(5));
30 println!("5th allocation now works: {:?}", box5);
31}pub fn into_raw(b: Self) -> NonNull<P::Item>
pub unsafe fn from_raw(ptr: NonNull<P::Item>) -> Self
Trait Implementations§
Source§impl<P: Pool> AsMutSlice for Box<P>where
P::Item: AsMutSlice,
impl<P: Pool> AsMutSlice for Box<P>where
P::Item: AsMutSlice,
Source§fn as_mut_slice(&mut self) -> &mut [Self::Element]
fn as_mut_slice(&mut self) -> &mut [Self::Element]
Returns the mutable slice view of
SelfSource§impl<P: Pool> AsMutSlice for Box<P>where
P::Item: AsMutSlice,
impl<P: Pool> AsMutSlice for Box<P>where
P::Item: AsMutSlice,
Source§fn as_mut_slice(&mut self) -> &mut [Self::Element]
fn as_mut_slice(&mut self) -> &mut [Self::Element]
Returns the mutable slice view of
SelfSource§impl<P: Pool> Ord for Box<P>
impl<P: Pool> Ord for Box<P>
Source§impl<P: Pool> PartialOrd for Box<P>where
P::Item: PartialOrd,
impl<P: Pool> PartialOrd for Box<P>where
P::Item: PartialOrd,
impl<P: Pool> Eq for Box<P>
impl<P: Pool> Send for Box<P>
impl<P: Pool> StableDeref for Box<P>
impl<P: Pool> Sync for Box<P>
Auto Trait Implementations§
impl<P> Freeze for Box<P>
impl<P> RefUnwindSafe for Box<P>
impl<P> Unpin for Box<P>
impl<P> UnwindSafe for Box<P>
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
Mutably borrows from an owned value. Read more