Struct rustler::resource::ResourceArc [] [src]

pub struct ResourceArc<T> where
    T: NifResourceTypeProvider, 
{ /* fields omitted */ }

A reference to a resource of type T.

This type is like std::sync::Arc: it provides thread-safe, reference-counted storage for Rust data that can be shared across threads. Data stored this way is immutable by default. If you need to modify data in a resource, use a std::sync::Mutex or RwLock.

Rust code and Erlang code can both have references to the same resource at the same time. Rust code uses ResourceArc; in Erlang, a reference to a resource is a kind of term. You can convert back and forth between the two using NifEncoder and NifDecoder.

Methods

impl<T> ResourceArc<T> where
    T: NifResourceTypeProvider, 
[src]

Makes a new ResourceArc from the given type. Note that the type must have NifResourceTypeProvider implemented for it. See module documentation for info on this.

Trait Implementations

impl<T> NifEncoder for ResourceArc<T> where
    T: NifResourceTypeProvider, 
[src]

impl<'a, T> NifDecoder<'a> for ResourceArc<T> where
    T: NifResourceTypeProvider + 'a, 
[src]

impl<T> Send for ResourceArc<T> where
    T: NifResourceTypeProvider, 
[src]

impl<T> Sync for ResourceArc<T> where
    T: NifResourceTypeProvider, 
[src]

impl<T> Deref for ResourceArc<T> where
    T: NifResourceTypeProvider, 
[src]

The resulting type after dereferencing

The method called to dereference a value

impl<T> Clone for ResourceArc<T> where
    T: NifResourceTypeProvider, 
[src]

Cloning a ResourceArc simply increments the reference count for the resource. The T value is not cloned.

Performs copy-assignment from source. Read more

impl<T> Drop for ResourceArc<T> where
    T: NifResourceTypeProvider, 
[src]

When a ResourceArc is dropped, the reference count is decremented. If there are no other references to the resource, the T value is dropped.

However, note that in general, the Rust value in a resource is dropped at an unpredictable time: whenever the VM decides to do garbage collection.