use std::{fmt::Debug, marker::PhantomData}; fn main() { let mut wrapper = Wrapper:: { value: Token::(PhantomData), _marker: PhantomData, game_state: GameState::Idle, }; let token: &mut Token = wrapper.token_mut(); let token: &Token = wrapper.token(); let game_state: &GameState = wrapper.game_state(); let game_state_mut: &mut GameState = wrapper.game_state_mut(); } struct Wrapper where T: Debug, { //#[hold] value: Token, //#[hold(GameStateHolder)] game_state: GameState, _marker: PhantomData, } impl TokenHolder for Wrapper where T: Debug, { fn token(&self) -> &Token { &self.value } fn token_mut(&mut self) -> &mut Token { &mut self.value } } impl GameStateHolder for Wrapper where T: Debug, { fn game_state<'a: 'b, 'b>(&'a self) -> &'b GameState { &self.game_state } fn game_state_mut(&mut self) -> &mut GameState { &mut self.game_state } } struct Token(PhantomData) where T: Debug; trait TokenHolder where T: Debug, { fn token(&self) -> &Token; fn token_mut(&mut self) -> &mut Token; } enum GameState { Idle, Play, } trait GameStateHolder { fn game_state<'a: 'b, 'b>(&'a self) -> &'b GameState; fn game_state_mut(&mut self) -> &mut GameState; }