Struct conc::Guard [] [src]

#[must_use = "You are getting a `conc::Guard` without using it, which means it is potentially unnecessary overhead. Consider replacing the method with something that doesn\'t return a guard."]
pub struct Guard<T: 'static + ?Sized> { /* fields omitted */ }

A RAII guard protecting from garbage collection.

This "guards" the held pointer against garbage collection. First when all guards of said pointer is gone (the data is unreachable), it can be collected.

Methods

impl<T: ?Sized> Guard<T>
[src]

(Failably) create a new guard.

This has all the same restrictions and properties as Guard::new() (please read its documentation before using), with the exception of being failable.

This means that the closure can return and error and abort the creation of the guard.

Create a new guard.

Because it must ensure that no garbage collection happens until the pointer is read, it takes a closure, which is evaluated to the pointer the guard will hold. During the span of this closure, garbage collection is ensured to not happen, making it safe to read from an atomic pointer without risking the ABA problem.

Important!

It is very important that this closure does not contain anything which might cause a garbage collection, as garbage collecting inside this closure will cause the current thread to be blocked infinitely (because the hazard is blocked) and stop all other threads from collecting garbage, leading to memory leaks in those.

Conditionally create a guard.

This acts try_new, but with Option instead of Result.

Map the pointer to another.

This allows one to map a pointer to a pointer e.g. to an object referenced by the old. It is very convenient for creating APIs without the need for creating a wrapper type.

Get the raw pointer of this guard.

Trait Implementations

impl<T: Debug + 'static + ?Sized> Debug for Guard<T>
[src]

Formats the value using the given formatter.

impl<T> PartialEq for Guard<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T> Eq for Guard<T>
[src]

impl<T> Deref for Guard<T>
[src]

The resulting type after dereferencing

The method called to dereference a value