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
AddressSpace
take&dyn DataSource
, e.g.: https://github.com/dylanmc/cs393_vm_api/blob/2d1299b1d4ee05cdcac73f3ef0ed3209fb9e85f1/src/address_space.rs#L43-L50But the struct itself stores
Arc<dyn DataSource>
: https://github.com/dylanmc/cs393_vm_api/blob/2d1299b1d4ee05cdcac73f3ef0ed3209fb9e85f1/src/address_space.rs#L9My instinct is that
add_mapping
should just take anArc
. The broader issue is that the methods ofDataSource
only have shared access toself
, and there's no way to safely upcast&self
toArc<self>
. So as I see it, either:DataSource
methods to have a stronger reference to self.MapType
needs to store&dyn DataSource
(maybe fine! TheDataSource
API is immutable anyway).&dyn DataSource
intoArc<dyn DataSource>
. This seems pretty unlikely to me.