[][src]Struct hulunbuir::Collector

pub struct Collector<T> { /* fields omitted */ }

Memory manager for allocation and garbage collection.

See module level document for basic usage.

Methods

impl<T: Keep> Collector<Slot<T>>[src]

pub fn take(&mut self, address: &Address) -> Result<Take<T>, Error>[src]

Take the object at address out and leave a hole there. Error::InvalidAddress will be thrown if there's no alive object at address.

impl<T> Collector<Slot<T>>[src]

pub fn fill(&mut self, address: &Address, value: T) -> Result<(), Error>[src]

Fill the hole at address with value. If the address does not contain a hole of an alive object, Error::InvalidAddress will be thrown. If there is already a not-in-used object at address, then Error::DuplicatedFilling will be thrown.

impl<T> Collector<T>[src]

pub fn new(slot_max: usize) -> Self[src]

Create a collector with slot_max slots available. Each slot is able to store a managed object typed T.

pub fn replace(&mut self, address: &Address, value: T) -> Result<T, Error>[src]

Replace the value of object at address with value. Return the original value of managed object. If there's no object at address (maybe the object there has been collected), throw Error::InvalidAddress.

pub fn set_root(&mut self, address: Address)[src]

Set object at address as root object. Only root object and objects kept by any object that has been considered as alive object in the current collecting pass will stay alive during garbage collection.

pub fn root(&self) -> &Option<Address>[src]

Return current root object. If no root object is set, return None, and every object will be collected if a collecting pass is triggered.

pub fn alive_count(&self) -> usize[src]

Return the total number of managed objects. Some of them may already be dead and will be collected in the following garbage collection.

impl<T: Keep> Collector<T>[src]

pub fn allocate(&mut self, value: T) -> Result<Address, Error>[src]

Create a new managed object with value. If there's no available slot a garbage collecting pass will be triggered. If there's still no available slot then Error::OutOfSlot will be thrown. Any error thrown by collecting process will be re-thrown.

pub fn collect(&mut self) -> Result<(), Error>[src]

Clean up all dead objects, which are unreachable from root object, or all objects if the root object is not set. If root object address is invalid, or any alive object keeps an object at invalid address, then Memory::InvalidAddress will be thrown.

This method will be invoked if Collector::allocate is called but no slot is available, but it could also be explicit called by user. Statistics log will be printed after each collecting pass.

Trait Implementations

impl<T: Debug> Debug for Collector<T>[src]

Auto Trait Implementations

impl<T> Sync for Collector<T> where
    T: Sync

impl<T> Send for Collector<T> where
    T: Send

impl<T> Unpin for Collector<T> where
    T: Unpin

impl<T> RefUnwindSafe for Collector<T> where
    T: RefUnwindSafe

impl<T> UnwindSafe for Collector<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]