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

pub struct ResourceArc<T> where
    T: ResourceTypeProvider, 
{ /* 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 Encoder and Decoder.

Methods

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

pub fn new(data: T) -> Self[src]

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

Trait Implementations

impl<T> Encoder for ResourceArc<T> where
    T: ResourceTypeProvider, 
[src]

impl<'a, T> Decoder<'a> for ResourceArc<T> where
    T: ResourceTypeProvider + 'a, 
[src]

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

fn drop(&mut self)[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.

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

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

fn clone(&self) -> Self[src]

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

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

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

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

type Target = T

The resulting type after dereferencing.

Blanket Implementations

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.