Struct janetrs::JanetGc

source ·
pub struct JanetGc { /* private fields */ }
Expand description

The Janet Garbage Collector type.

It allows the use of garbage collection operations in the Janet public C API.

Implementations§

source§

impl JanetGc

source

pub fn obtain() -> Self

Obtain the JanetGc.

source

pub unsafe fn collect(&self)

Run the garbage collection if there is nothing locking or suspending the garbage collector, like an active JanetGcLockGuard or a call to a Janet C API that locks the GC.

If there is something locking the garbage collection, it simply does a no-op.

§Safety

This function will free all memory allocated with the Janet scratch memory API and any non-rooted object that have no reference to a live object (as example, an empty JanetTable or JanetArray )

source

pub fn lock(&self) -> JanetGcLockGuard

Lock the Janet GC and suspend any garbage collection until the guard is dropped.

If there is any attempt to manually trigger the garbage collection while there is a JanetGcLockGuard active (or any unsafe call to the Janet C API locking the GC)

source

pub fn unlock(guard: JanetGcLockGuard)

Immediately drops the guard, and consequently unlocks the Janet GC.

This function is equivalent to calling drop on the guard but is more self-documenting. Alternately, the guard will be automatically dropped when it goes out of scope.

§Example:
use janetrs::JanetGc;

let gc = JanetGc::obtain();

let mut guard = gc.lock();

// do stuff with the Janet GC locked

JanetGc::unlock(guard);
source

pub fn root(&self, value: Janet) -> JanetGcRootGuard

Roots the value to the GC. This prevents the GC from removing the value and all of its children in a garbage collection.

The returned guard will unroot the value when dropped.

source

pub fn unroot(guard: JanetGcRootGuard)

Immediately drops the guard, and consequently unlocks the Janet GC.

This function is equivalent to calling drop on the guard but is more self-documenting. Alternately, the guard will be automatically dropped when it goes out of scope.

Trait Implementations§

source§

impl Debug for JanetGc

source§

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

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

impl Default for JanetGc

source§

fn default() -> JanetGc

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

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.