Skip to main content

ResourceTable

Struct ResourceTable 

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

The ResourceTable type maps a Resource<T> to its T.

Implementations§

Source§

impl ResourceTable

Source

pub fn new() -> ResourceTable

Create an empty table

Source

pub fn is_empty(&self) -> bool

Returns whether or not this table is empty.

Note that this is an O(n) operation, where n is the number of entries in the backing Vec.

Source

pub fn with_capacity(capacity: usize) -> ResourceTable

Create an empty table with at least the specified capacity.

Source

pub fn push<T>(&mut self, entry: T) -> Result<Resource<T>, ResourceTableError>
where T: Send + 'static,

Inserts a new value T into this table, returning a corresponding Resource<T> which can be used to refer to it after it was inserted.

Source

pub fn push_child<T, U>( &mut self, entry: T, parent: &Resource<U>, ) -> Result<Resource<T>, ResourceTableError>
where T: Send + 'static, U: 'static,

Insert a resource at the next available index, and track that it has a parent resource.

The parent must exist to create a child. All children resources must be destroyed before a parent can be destroyed - otherwise ResourceTable::delete will fail with ResourceTableError::HasChildren.

Parent-child relationships are tracked inside the table to ensure that a parent resource is not deleted while it has live children. This allows child resources to hold “references” to a parent by table index, to avoid needing e.g. an Arc<Mutex<parent>> and the associated locking overhead and design issues, such as child existence extending lifetime of parent referent even after parent resource is destroyed, possibility for deadlocks.

Source

pub fn add_child<T, U>( &mut self, child: Resource<T>, parent: Resource<U>, ) -> Result<(), ResourceTableError>
where T: 'static, U: 'static,

Add an already-resident child to a resource.

Source

pub fn remove_child<T, U>( &mut self, child: Resource<T>, parent: Resource<U>, ) -> Result<(), ResourceTableError>
where T: 'static, U: 'static,

Remove a child to from a resource (but leave it in the table).

Source

pub fn get<T>(&self, key: &Resource<T>) -> Result<&T, ResourceTableError>
where T: Any,

Get an immutable reference to a resource of a given type at a given index.

Multiple shared references can be borrowed at any given time.

Source

pub fn get_mut<T>( &mut self, key: &Resource<T>, ) -> Result<&mut T, ResourceTableError>
where T: Any,

Get an mutable reference to a resource of a given type at a given index.

Source

pub fn get_any_mut( &mut self, key: u32, ) -> Result<&mut (dyn Any + 'static), ResourceTableError>

Returns the raw Any at the key index provided.

Source

pub fn delete<T>( &mut self, resource: Resource<T>, ) -> Result<T, ResourceTableError>
where T: Any,

Remove the specified entry from the table.

Source

pub fn iter_entries<'a, T>( &'a mut self, map: BTreeMap<u32, T>, ) -> impl Iterator<Item = (Result<&'a mut (dyn Any + 'static), ResourceTableError>, T)>

Zip the values of the map with mutable references to table entries corresponding to each key. As the keys in the BTreeMap are unique, this iterator can give mutable references with the same lifetime as the mutable reference to the ResourceTable.

Source

pub fn iter_children<T>( &self, parent: &Resource<T>, ) -> Result<impl Iterator<Item = &(dyn Any + Send + 'static)> + use<'_, T>, ResourceTableError>
where T: 'static,

Iterate over all children belonging to the provided parent

Source

pub fn iter_mut( &mut self, ) -> impl Iterator<Item = &mut (dyn Any + Send + 'static)>

Iterate over all the entries in this table.

Trait Implementations§

Source§

impl Debug for ResourceTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for ResourceTable

Source§

fn default() -> ResourceTable

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

impl Host for ResourceTable

Source§

fn poll( &mut self, pollables: Vec<Resource<DynPollable>>, ) -> Result<Vec<u32>, Error>

Poll for completion on a set of pollables. Read more
Source§

impl Host for ResourceTable

Source§

impl Host for ResourceTable

Source§

async fn poll( &mut self, pollables: Vec<Resource<DynPollable>>, ) -> Result<Vec<u32>, Error>

Poll for completion on a set of pollables. Read more
Source§

impl Host for ResourceTable

Source§

impl HostError for ResourceTable

Source§

fn drop(&mut self, err: Resource<Error>) -> Result<(), Error>

Source§

fn to_debug_string(&mut self, err: Resource<Error>) -> Result<String, Error>

Returns a string that is suitable to assist humans in debugging this error. Read more
Source§

impl HostInputStream for ResourceTable

Source§

fn drop(&mut self, stream: Resource<Box<dyn InputStream>>) -> Result<(), Error>

Source§

fn read( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<Vec<u8>, StreamError>

Perform a non-blocking read from the stream. Read more
Source§

fn blocking_read( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<Vec<u8>, StreamError>

Read bytes from a stream, after blocking until at least one byte can be read. Except for blocking, behavior is identical to read.
Source§

fn skip( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>

Skip bytes from a stream. Returns number of bytes skipped. Read more
Source§

fn blocking_skip( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>

Skip bytes from a stream, after blocking until at least one byte can be skipped. Except for blocking behavior, identical to skip.
Source§

fn subscribe( &mut self, stream: Resource<Box<dyn InputStream>>, ) -> Result<Resource<DynPollable>, Error>

Create a pollable which will resolve once either the specified stream has bytes available to read or the other end of the stream has been closed. The created pollable is a child resource of the input-stream. Implementations may trap if the input-stream is dropped before all derived pollables created with this function are dropped.
Source§

impl HostInputStream for ResourceTable

Source§

async fn drop( &mut self, stream: Resource<Box<dyn InputStream>>, ) -> Result<(), Error>

Source§

fn read( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<Vec<u8>, StreamError>

Perform a non-blocking read from the stream. Read more
Source§

async fn blocking_read( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<Vec<u8>, StreamError>

Read bytes from a stream, after blocking until at least one byte can be read. Except for blocking, behavior is identical to read.
Source§

fn skip( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>

Skip bytes from a stream. Returns number of bytes skipped. Read more
Source§

async fn blocking_skip( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>

Skip bytes from a stream, after blocking until at least one byte can be skipped. Except for blocking behavior, identical to skip.
Source§

fn subscribe( &mut self, stream: Resource<Box<dyn InputStream>>, ) -> Result<Resource<DynPollable>, Error>

Create a pollable which will resolve once either the specified stream has bytes available to read or the other end of the stream has been closed. The created pollable is a child resource of the input-stream. Implementations may trap if the input-stream is dropped before all derived pollables created with this function are dropped.
Source§

impl HostOutputStream for ResourceTable

Source§

fn drop(&mut self, stream: Resource<Box<dyn OutputStream>>) -> Result<(), Error>

Source§

fn check_write( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<u64, StreamError>

Check readiness for writing. This function never blocks. Read more
Source§

fn write( &mut self, stream: Resource<Box<dyn OutputStream>>, bytes: Vec<u8>, ) -> Result<(), StreamError>

Perform a write. This function never blocks. Read more
Source§

fn blocking_write_and_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, bytes: Vec<u8>, ) -> Result<(), StreamError>

Perform a write of up to 4096 bytes, and then flush the stream. Block until all of these operations are complete, or an error occurs. Read more
Source§

fn blocking_write_zeroes_and_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, len: u64, ) -> Result<(), StreamError>

Perform a write of up to 4096 zeroes, and then flush the stream. Block until all of these operations are complete, or an error occurs. Read more
Source§

fn subscribe( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<Resource<DynPollable>, Error>

Create a pollable which will resolve once the output-stream is ready for more writing, or an error has occurred. When this pollable is ready, check-write will return ok(n) with n>0, or an error. Read more
Source§

fn write_zeroes( &mut self, stream: Resource<Box<dyn OutputStream>>, len: u64, ) -> Result<(), StreamError>

Write zeroes to a stream. Read more
Source§

fn flush( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), StreamError>

Request to flush buffered output. This function never blocks. Read more
Source§

fn blocking_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), StreamError>

Request to flush buffered output, and block until flush completes and stream is ready for writing again.
Source§

fn splice( &mut self, dst: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>

Read from one stream and write to another. Read more
Source§

fn blocking_splice( &mut self, dst: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>

Read from one stream and write to another, with blocking. Read more
Source§

impl HostOutputStream for ResourceTable

Source§

async fn drop( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), Error>

Source§

fn check_write( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<u64, StreamError>

Check readiness for writing. This function never blocks. Read more
Source§

fn write( &mut self, stream: Resource<Box<dyn OutputStream>>, bytes: Vec<u8>, ) -> Result<(), StreamError>

Perform a write. This function never blocks. Read more
Source§

fn subscribe( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<Resource<DynPollable>, Error>

Create a pollable which will resolve once the output-stream is ready for more writing, or an error has occurred. When this pollable is ready, check-write will return ok(n) with n>0, or an error. Read more
Source§

async fn blocking_write_and_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, bytes: Vec<u8>, ) -> Result<(), StreamError>

Perform a write of up to 4096 bytes, and then flush the stream. Block until all of these operations are complete, or an error occurs. Read more
Source§

async fn blocking_write_zeroes_and_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, len: u64, ) -> Result<(), StreamError>

Perform a write of up to 4096 zeroes, and then flush the stream. Block until all of these operations are complete, or an error occurs. Read more
Source§

fn write_zeroes( &mut self, stream: Resource<Box<dyn OutputStream>>, len: u64, ) -> Result<(), StreamError>

Write zeroes to a stream. Read more
Source§

fn flush( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), StreamError>

Request to flush buffered output. This function never blocks. Read more
Source§

async fn blocking_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), StreamError>

Request to flush buffered output, and block until flush completes and stream is ready for writing again.
Source§

fn splice( &mut self, dest: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>

Read from one stream and write to another. Read more
Source§

async fn blocking_splice( &mut self, dest: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>

Read from one stream and write to another, with blocking. Read more
Source§

impl HostPollable for ResourceTable

Source§

fn ready(&mut self, pollable: Resource<DynPollable>) -> Result<bool, Error>

Return the readiness of a pollable. This function never blocks. Read more
Source§

fn block(&mut self, pollable: Resource<DynPollable>) -> Result<(), Error>

block returns immediately if the pollable is ready, and otherwise blocks until ready. Read more
Source§

fn drop(&mut self, pollable: Resource<DynPollable>) -> Result<(), Error>

Source§

impl HostPollable for ResourceTable

Source§

async fn block(&mut self, pollable: Resource<DynPollable>) -> Result<(), Error>

block returns immediately if the pollable is ready, and otherwise blocks until ready. Read more
Source§

async fn ready( &mut self, pollable: Resource<DynPollable>, ) -> Result<bool, Error>

Return the readiness of a pollable. This function never blocks. Read more
Source§

fn drop(&mut self, pollable: Resource<DynPollable>) -> Result<(), Error>

Source§

impl Host for ResourceTable

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> GetSetFdFlags for T

Source§

fn get_fd_flags(&self) -> Result<FdFlags, Error>
where T: AsFilelike,

Query the “status” flags for the self file descriptor.
Source§

fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>
where T: AsFilelike,

Create a new SetFdFlags value for use with set_fd_flags. Read more
Source§

fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>
where T: AsFilelike,

Set the “status” flags for the self file descriptor. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more