[][src]Struct deno_core::ResourceTable

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 has(&self, rid: u32) -> bool[src]

Checks if the given resource ID is contained.

pub fn get<T: Any>(&self, rid: u32) -> Option<&T>[src]

Returns a shared reference to a resource.

Returns None, if rid is not stored or has a type different from T.

pub fn get_mut<T: Any>(&mut self, rid: u32) -> Option<&mut T>[src]

Returns a mutable reference to a resource.

Returns None, if rid is not stored or has a type different from T.

pub fn add(&mut self, name: &str, resource: Box<dyn Any>) -> u32[src]

Inserts a resource, taking 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 entries(&self) -> HashMap<u32, String>[src]

Returns a map of resource IDs to names.

The name is the one specified during add(). To access resources themselves, use the get() or get_mut() functions.

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

pub fn remove<T: Any>(&mut self, rid: u32) -> Option<Box<T>>[src]

Removes the resource identified by rid and returns it.

When the provided rid is stored, the associated resource will be removed. Otherwise, nothing happens and None is returned.

If the type T matches the resource's type, the resource will be returned. If the type mismatches, None is returned, but the resource is still removed.

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.