Struct deno_core::ResourceTable[][src]

pub struct ResourceTable { /* fields omitted */ }

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

impl ResourceTable[src]

pub fn add<T: Resource>(&mut self, resource: T) -> ResourceId[src]

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.

pub fn add_rc<T: Resource>(&mut self, resource: Rc<T>) -> ResourceId[src]

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.

pub fn has(&self, rid: ResourceId) -> bool[src]

Returns true if any resource with the given rid exists.

pub fn get<T: Resource>(&self, rid: ResourceId) -> Option<Rc<T>>[src]

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.

pub fn get_any(&self, rid: ResourceId) -> Option<Rc<dyn Resource>>[src]

pub fn take<T: Resource>(&mut self, rid: ResourceId) -> Option<Rc<T>>[src]

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.

pub fn take_any(&mut self, rid: ResourceId) -> Option<Rc<dyn Resource>>[src]

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

pub fn close(&mut self, rid: ResourceId) -> Option<()>[src]

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.

pub fn names(&self) -> impl Iterator<Item = (ResourceId, Cow<'_, str>)>[src]

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

impl Default for ResourceTable[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.