pub struct ResourceArc<T>where
    T: ResourceTypeProvider,
{ /* private fields */ }
Expand description

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.

Implementations§

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.

Make a resource binary associated with the given resource

The closure f is called with the referenced object and must return a slice with the same lifetime as the object. This means that the slice either has to be derived directly from the instance or that it has to have static lifetime.

Make a resource binary without strict lifetime checking

The user must ensure that the lifetime of the returned slice is at least as long as the lifetime of the referenced instance.

Safety

This function is only safe if the slice that is returned from the closure is guaranteed to live at least as long as the ResourceArc instance. If in doubt, use the safe version ResourceArc::make_binary which enforces this bound through its signature.

Trait Implementations§

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

Performs copy-assignment from source. Read more
The resulting type after dereferencing.
Dereferences the value.

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.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.