pub struct ResourceTable { /* private fields */ }
Expand description

Map-like data structure storing Deno’s resources (equivalent to file descriptors).

Provides basic methods for element access. A resource can be of any type. Different types of resources can be stored in the same map, and provided with a name for description.

Each resource is identified through a resource ID (rid), which acts as the key in the map.

Implementations§

Inserts resource into the resource table, which takes ownership of it.

The resource type is erased at runtime and must be statically known when retrieving it through get().

Returns a unique resource ID, which acts as a key for this resource.

Inserts a Rc-wrapped resource into the resource table.

The resource type is erased at runtime and must be statically known when retrieving it through get().

Returns a unique resource ID, which acts as a key for this resource.

Returns true if any resource with the given rid exists.

Returns a reference counted pointer to the resource of type T with the given rid. If rid is not present or has a type different than T, this function returns None.

Replaces a resource with a new resource.

Panics if the resource does not exist.

Removes a resource of type T from the resource table and returns it. If a resource with the given rid exists but its type does not match T, it is not removed from the resource table. Note that the resource’s close() method is not called.

Removes a resource from the resource table and returns it. Note that the resource’s close() method is not called.

Removes the resource with the given rid from the resource table. If the only reference to this resource existed in the resource table, this will cause the resource to be dropped. However, since resources are reference counted, therefore pending ops are not automatically cancelled. A resource may implement the close() method to perform clean-ups such as canceling ops.

Returns an iterator that yields a (id, name) pair for every resource that’s currently in the resource table. This can be used for debugging purposes or to implement the op_resources op. Note that the order in which items appear is not specified.

Example
let resource_names = resource_table.names().collect::<Vec<_>>();

Trait Implementations§

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

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