ResourceSystem

Struct ResourceSystem 

Source
pub struct ResourceSystem<S: ProcessSpawner, R: Runtime> { /* private fields */ }
Available on crate feature vmm-core only.
Expand description

A ResourceSystem represents a non-cloneable object connected to a background task running on a Runtime. This task is a central task that responds to messages from the connected ResourceSystem and Resources and spawns various auxiliary tasks onto the same Runtime that perform asynchronous resource actions such as initialization and disposal.

The ResourceSystem allows the creation of new Resources and global synchronization with the task. After being dropped, the ResourceSystem will transmit a shutdown message that will end the task. The ResourceSystem requires not only a Runtime, but also a ProcessSpawner and a VmmOwnershipModel in order to perform its functionality, and these objects will be used by VMs and VMM processes that internally embed a ResourceSystem.

Implementations§

Source§

impl<S: ProcessSpawner, R: Runtime> ResourceSystem<S, R>

Source

pub fn new( process_spawner: S, runtime: R, ownership_model: VmmOwnershipModel, ) -> Self

Create a new ResourceSystem with empty buffers for storing resource objects, using the given ProcessSpawner, Runtime and VmmOwnershipModel.

Source

pub fn with_capacity( process_spawner: S, runtime: R, ownership_model: VmmOwnershipModel, capacity: usize, ) -> Self

Create a new ResourceSystem with pre-reserved buffers of a certain capacity for storing resource objects, using the given ProcessSpawner, Runtime and VmmOwnershipModel.

Source

pub fn get_resources(&self) -> &[Resource]

Get a shared slice into an internal buffer that contains all Resources within this ResourceSystem, not including any clones of given out Resources. This slice can be cloned to produce a Vec if owned Resource instances are needed, but, by default, no cloning occurs when calling this function.

Source

pub fn create_resource<P: Into<PathBuf>>( &mut self, initial_path: P, type: ResourceType, ) -> Result<Resource, ResourceSystemError>

Create a Resource in this ResourceSystem from a given initial path and a ResourceType. The data will immediately be transmitted to the ResourceSystem’s central task, and an extra Resource clone will be stored inside the buffer accessible via get_resources.

Source

pub async fn synchronize(&mut self) -> Result<(), ResourceSystemError>

Performs manual synchronization with the underlying central task. This operation waits until all initialization, disposal or other scheduled tasks complete. If all such tasks complete successfully, Ok is returned. If only one such task fails and all others succeed, a standard ResourceSystemError is returned. If multiple such tasks fail, a ResourceSystemError::ErrorChain variant is returned, encompassing multiple inner ResourceSystemErrors for each failed task.

Trait Implementations§

Source§

impl<S: Debug + ProcessSpawner, R: Debug + Runtime> Debug for ResourceSystem<S, R>

Source§

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

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

impl<S: ProcessSpawner, R: Runtime> Drop for ResourceSystem<S, R>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<S, R> Freeze for ResourceSystem<S, R>
where S: Freeze, R: Freeze,

§

impl<S, R> !RefUnwindSafe for ResourceSystem<S, R>

§

impl<S, R> Send for ResourceSystem<S, R>

§

impl<S, R> Sync for ResourceSystem<S, R>

§

impl<S, R> Unpin for ResourceSystem<S, R>
where S: Unpin, R: Unpin,

§

impl<S, R> !UnwindSafe for ResourceSystem<S, R>

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<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> 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> 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, 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<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