I feel like what you're looking for is generic mutability.
With that, you could write this code (syntax to be bikeshedded):
pub fn get_some_ref<M: Mutability>( &gen<M> self, key: i32 ) -> &gen<M> i32 {
if key == 42 {
&gen self.data1
} else {
&gen self.data2
}
}
I personally would love to have this in the language (I'm currently working on a generic mutability crate, not released yet), although many say it's not worth the price and using macros for this is fine.