Struct rsim::processor::isa_mods::csrs::ZicsrConn [−][src]
pub struct ZicsrConn<'a, T> where
T: From<u8>, { pub sreg: &'a mut dyn RegisterFile<T>, pub csr_providers: Vec<&'a mut dyn CSRProvider<T>>, }
References to all CSR providers
Fields
sreg: &'a mut dyn RegisterFile<T>
csr_providers: Vec<&'a mut dyn CSRProvider<T>>
Implementations
impl<'a, T> ZicsrConn<'a, T> where
T: From<u8>,
[src]
impl<'a, T> ZicsrConn<'a, T> where
T: From<u8>,
[src]fn provider_of_csr(
&mut self,
csr: u32
) -> Option<&mut &'a mut dyn CSRProvider<T>>
[src]
&mut self,
csr: u32
) -> Option<&mut &'a mut dyn CSRProvider<T>>
Explanation of return type: OK, so this is really annoying.
We want to return a reference to one of the mutrefs inside csr_providers.
However, we can’t just copy the mutref out, because that would mean two copies exist - one in csr_providers, and one in our return value.
=> we have to return a reference to the mutref - &(&'a mut dyn CSRProvider)
.
Because we want to modify the thing at the end of the mutref, Rust complains and wants the outer reference to be mutable as well.
=> & mut (&'a mut dyn CSRProvider)
And, because we may not find anything, wrap the whole thing in an Option
=> Option<& mut &'a mut dyn CSRProvider>