pub struct ResourceTable { /* private fields */ }Expand description
The ResourceTable type maps a Resource<T> to its T.
Implementations§
Source§impl ResourceTable
impl ResourceTable
Sourcepub fn new() -> ResourceTable
pub fn new() -> ResourceTable
Create an empty table
Sourcepub fn is_empty(&self) -> bool
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.
Sourcepub fn with_capacity(capacity: usize) -> ResourceTable
pub fn with_capacity(capacity: usize) -> ResourceTable
Create an empty table with at least the specified capacity.
Sourcepub fn push<T>(&mut self, entry: T) -> Result<Resource<T>, ResourceTableError>where
T: Send + 'static,
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.
Sourcepub fn push_child<T, U>(
&mut self,
entry: T,
parent: &Resource<U>,
) -> Result<Resource<T>, ResourceTableError>where
T: Send + 'static,
U: 'static,
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.
Sourcepub fn add_child<T, U>(
&mut self,
child: Resource<T>,
parent: Resource<U>,
) -> Result<(), ResourceTableError>where
T: 'static,
U: 'static,
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.
Sourcepub fn remove_child<T, U>(
&mut self,
child: Resource<T>,
parent: Resource<U>,
) -> Result<(), ResourceTableError>where
T: 'static,
U: 'static,
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).
Sourcepub fn get<T>(&self, key: &Resource<T>) -> Result<&T, ResourceTableError>where
T: Any,
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.
Sourcepub fn get_mut<T>(
&mut self,
key: &Resource<T>,
) -> Result<&mut T, ResourceTableError>where
T: Any,
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.
Sourcepub fn get_any_mut(
&mut self,
key: u32,
) -> Result<&mut (dyn Any + 'static), ResourceTableError>
pub fn get_any_mut( &mut self, key: u32, ) -> Result<&mut (dyn Any + 'static), ResourceTableError>
Returns the raw Any at the key index provided.
Sourcepub fn delete<T>(
&mut self,
resource: Resource<T>,
) -> Result<T, ResourceTableError>where
T: Any,
pub fn delete<T>(
&mut self,
resource: Resource<T>,
) -> Result<T, ResourceTableError>where
T: Any,
Remove the specified entry from the table.
Sourcepub fn iter_entries<'a, T>(
&'a mut self,
map: BTreeMap<u32, T>,
) -> impl Iterator<Item = (Result<&'a mut (dyn Any + 'static), ResourceTableError>, T)>
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.
Sourcepub fn iter_children<T>(
&self,
parent: &Resource<T>,
) -> Result<impl Iterator<Item = &(dyn Any + Send + 'static)> + use<'_, T>, ResourceTableError>where
T: 'static,
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
Trait Implementations§
Source§impl Debug for ResourceTable
impl Debug for ResourceTable
Source§impl Default for ResourceTable
impl Default for ResourceTable
Source§fn default() -> ResourceTable
fn default() -> ResourceTable
Source§impl Host for ResourceTable
impl Host for ResourceTable
Source§impl Host for ResourceTable
impl Host for ResourceTable
fn convert_stream_error( &mut self, err: StreamError, ) -> Result<StreamError, Error>
Source§impl Host for ResourceTable
impl Host for ResourceTable
Source§impl Host for ResourceTable
impl Host for ResourceTable
fn convert_stream_error( &mut self, err: StreamError, ) -> Result<StreamError, Error>
Source§impl HostError for ResourceTable
impl HostError for ResourceTable
Source§impl HostInputStream for ResourceTable
impl HostInputStream for ResourceTable
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>
fn read( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<Vec<u8>, StreamError>
Source§fn blocking_read(
&mut self,
stream: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<Vec<u8>, StreamError>
fn blocking_read( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<Vec<u8>, StreamError>
read.Source§fn skip(
&mut self,
stream: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<u64, StreamError>
fn skip( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
Source§fn blocking_skip(
&mut self,
stream: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<u64, StreamError>
fn blocking_skip( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
skip.Source§fn subscribe(
&mut self,
stream: Resource<Box<dyn InputStream>>,
) -> Result<Resource<DynPollable>, Error>
fn subscribe( &mut self, stream: Resource<Box<dyn InputStream>>, ) -> Result<Resource<DynPollable>, Error>
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
impl HostInputStream for ResourceTable
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>
fn read( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<Vec<u8>, StreamError>
Source§async fn blocking_read(
&mut self,
stream: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<Vec<u8>, StreamError>
async fn blocking_read( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<Vec<u8>, StreamError>
read.Source§fn skip(
&mut self,
stream: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<u64, StreamError>
fn skip( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
Source§async fn blocking_skip(
&mut self,
stream: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<u64, StreamError>
async fn blocking_skip( &mut self, stream: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
skip.Source§fn subscribe(
&mut self,
stream: Resource<Box<dyn InputStream>>,
) -> Result<Resource<DynPollable>, Error>
fn subscribe( &mut self, stream: Resource<Box<dyn InputStream>>, ) -> Result<Resource<DynPollable>, Error>
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
impl HostOutputStream for ResourceTable
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>
fn check_write( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<u64, StreamError>
Source§fn write(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
bytes: Vec<u8>,
) -> Result<(), StreamError>
fn write( &mut self, stream: Resource<Box<dyn OutputStream>>, bytes: Vec<u8>, ) -> Result<(), StreamError>
Source§fn blocking_write_and_flush(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
bytes: Vec<u8>,
) -> Result<(), StreamError>
fn blocking_write_and_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, bytes: Vec<u8>, ) -> Result<(), StreamError>
Source§fn blocking_write_zeroes_and_flush(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
len: u64,
) -> Result<(), StreamError>
fn blocking_write_zeroes_and_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, len: u64, ) -> Result<(), StreamError>
Source§fn subscribe(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
) -> Result<Resource<DynPollable>, Error>
fn subscribe( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<Resource<DynPollable>, Error>
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 moreSource§fn write_zeroes(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
len: u64,
) -> Result<(), StreamError>
fn write_zeroes( &mut self, stream: Resource<Box<dyn OutputStream>>, len: u64, ) -> Result<(), StreamError>
Source§fn flush(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
) -> Result<(), StreamError>
fn flush( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), StreamError>
Source§fn blocking_flush(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
) -> Result<(), StreamError>
fn blocking_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), StreamError>
Source§fn splice(
&mut self,
dst: Resource<Box<dyn OutputStream>>,
src: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<u64, StreamError>
fn splice( &mut self, dst: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
Source§fn blocking_splice(
&mut self,
dst: Resource<Box<dyn OutputStream>>,
src: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<u64, StreamError>
fn blocking_splice( &mut self, dst: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
Source§impl HostOutputStream for ResourceTable
impl HostOutputStream for ResourceTable
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>
fn check_write( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<u64, StreamError>
Source§fn write(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
bytes: Vec<u8>,
) -> Result<(), StreamError>
fn write( &mut self, stream: Resource<Box<dyn OutputStream>>, bytes: Vec<u8>, ) -> Result<(), StreamError>
Source§fn subscribe(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
) -> Result<Resource<DynPollable>, Error>
fn subscribe( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<Resource<DynPollable>, Error>
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 moreSource§async fn blocking_write_and_flush(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
bytes: Vec<u8>,
) -> Result<(), StreamError>
async fn blocking_write_and_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, bytes: Vec<u8>, ) -> Result<(), StreamError>
Source§async fn blocking_write_zeroes_and_flush(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
len: u64,
) -> Result<(), StreamError>
async fn blocking_write_zeroes_and_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, len: u64, ) -> Result<(), StreamError>
Source§fn write_zeroes(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
len: u64,
) -> Result<(), StreamError>
fn write_zeroes( &mut self, stream: Resource<Box<dyn OutputStream>>, len: u64, ) -> Result<(), StreamError>
Source§fn flush(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
) -> Result<(), StreamError>
fn flush( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), StreamError>
Source§async fn blocking_flush(
&mut self,
stream: Resource<Box<dyn OutputStream>>,
) -> Result<(), StreamError>
async fn blocking_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), StreamError>
Source§fn splice(
&mut self,
dest: Resource<Box<dyn OutputStream>>,
src: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<u64, StreamError>
fn splice( &mut self, dest: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
Source§async fn blocking_splice(
&mut self,
dest: Resource<Box<dyn OutputStream>>,
src: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<u64, StreamError>
async fn blocking_splice( &mut self, dest: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
Source§impl HostPollable for ResourceTable
impl HostPollable for ResourceTable
Source§fn ready(&mut self, pollable: Resource<DynPollable>) -> Result<bool, Error>
fn ready(&mut self, pollable: Resource<DynPollable>) -> Result<bool, Error>
Source§fn block(&mut self, pollable: Resource<DynPollable>) -> Result<(), Error>
fn block(&mut self, pollable: Resource<DynPollable>) -> Result<(), Error>
block returns immediately if the pollable is ready, and otherwise
blocks until ready. Read morefn drop(&mut self, pollable: Resource<DynPollable>) -> Result<(), Error>
Source§impl HostPollable for ResourceTable
impl HostPollable for ResourceTable
Source§async fn block(&mut self, pollable: Resource<DynPollable>) -> Result<(), Error>
async fn block(&mut self, pollable: Resource<DynPollable>) -> Result<(), Error>
block returns immediately if the pollable is ready, and otherwise
blocks until ready. Read moreSource§async fn ready(
&mut self,
pollable: Resource<DynPollable>,
) -> Result<bool, Error>
async fn ready( &mut self, pollable: Resource<DynPollable>, ) -> Result<bool, Error>
fn drop(&mut self, pollable: Resource<DynPollable>) -> Result<(), Error>
impl Host for ResourceTable
Auto Trait Implementations§
impl Freeze for ResourceTable
impl !RefUnwindSafe for ResourceTable
impl Send for ResourceTable
impl !Sync for ResourceTable
impl Unpin for ResourceTable
impl !UnwindSafe for ResourceTable
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request