pub struct ResourceSystem<S: ProcessSpawner, R: Runtime> { /* private fields */ }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>
impl<S: ProcessSpawner, R: Runtime> ResourceSystem<S, R>
Sourcepub fn new(
process_spawner: S,
runtime: R,
ownership_model: VmmOwnershipModel,
) -> Self
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.
Sourcepub fn with_capacity(
process_spawner: S,
runtime: R,
ownership_model: VmmOwnershipModel,
capacity: usize,
) -> Self
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.
Sourcepub fn get_resources(&self) -> &[Resource]
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.
Sourcepub fn create_resource<P: Into<PathBuf>>(
&mut self,
initial_path: P,
type: ResourceType,
) -> Result<Resource, ResourceSystemError>
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.
Sourcepub async fn synchronize(&mut self) -> Result<(), ResourceSystemError>
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>
impl<S: Debug + ProcessSpawner, R: Debug + Runtime> Debug for ResourceSystem<S, R>
Source§impl<S: ProcessSpawner, R: Runtime> Drop for ResourceSystem<S, R>
impl<S: ProcessSpawner, R: Runtime> Drop for ResourceSystem<S, R>
Auto Trait Implementations§
impl<S, R> Freeze for ResourceSystem<S, R>
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>
impl<S, R> !UnwindSafe for ResourceSystem<S, R>
Blanket Implementations§
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> 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> 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