Skip to main content

Resource

Trait Resource 

Source
pub trait Resource:
    Send
    + Sync
    + Debug
    + 'static {
    // Required methods
    fn close(&self) -> ValueResult<()>;
    fn is_closed(&self) -> bool;
    fn resource_type(&self) -> &'static str;
    fn as_any(&self) -> &dyn Any;
}
Expand description

A closeable, ref-counted resource (file handle, socket, etc.).

All methods take &self because the inner state is behind a Mutex.

Required Methods§

Source

fn close(&self) -> ValueResult<()>

Close the resource. Idempotent — calling on an already-closed resource is a no-op.

Source

fn is_closed(&self) -> bool

Whether this resource has been closed.

Source

fn resource_type(&self) -> &'static str

A short tag for display, e.g. "reader", "writer".

Source

fn as_any(&self) -> &dyn Any

Downcast support so native fns can get the concrete type.

Implementors§