The methods of AddressSpace take &dyn DataSource, e.g.:
|
pub fn add_mapping( |
|
&self, |
|
source: &dyn DataSource, |
|
offset: usize, |
|
span: usize, |
|
) -> Result<VirtualAddress, &str> { |
|
todo!() |
|
} |
But the struct itself stores Arc<dyn DataSource>:
|
source: Arc<dyn DataSource>, |
My instinct is that add_mapping should just take an Arc. The broader issue is that the methods of DataSource only have shared access to self, and there's no way to safely upcast &self to Arc<self>. So as I see it, either:
- The
DataSource methods to have a stronger reference to self.
MapType needs to store &dyn DataSource (maybe fine! The DataSource API is immutable anyway).
- There's some clever invariant that will make it ok to unsafely mutate
&dyn DataSource into Arc<dyn DataSource>. This seems pretty unlikely to me.
The methods of
AddressSpacetake&dyn DataSource, e.g.:cs393_vm_api/src/address_space.rs
Lines 43 to 50 in 2d1299b
But the struct itself stores
Arc<dyn DataSource>:cs393_vm_api/src/address_space.rs
Line 9 in 2d1299b
My instinct is that
add_mappingshould just take anArc. The broader issue is that the methods ofDataSourceonly have shared access toself, and there's no way to safely upcast&selftoArc<self>. So as I see it, either:DataSourcemethods to have a stronger reference to self.MapTypeneeds to store&dyn DataSource(maybe fine! TheDataSourceAPI is immutable anyway).&dyn DataSourceintoArc<dyn DataSource>. This seems pretty unlikely to me.