-
-
Save Lytigas/dc26f5c7a5f48676c46eca7d639b1690 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct SharedState { | |
data: HashMap<KeyType, ValueType>, | |
msg_buf: Vec<Message<'static>>, | |
} | |
struct VecHolder<'a, 'b: 'a>(&'a mut Vec<Message<'b>>); | |
impl<'a, 'b: 'a> VecHolder<'a, 'b> { | |
pub fn new<'o>(other: &'a mut Vec<Message<'o>>) -> Self { | |
Self(unsafe { std::mem::transmute(other) }) | |
} | |
pub fn inner<'d, 'e: 'd>(&'e mut self) -> &'d mut Vec<Message<'b>> { | |
self.0 | |
} | |
} | |
impl<'a, 'b> Drop for VecHolder<'a, 'b> { | |
fn drop(&mut self) { | |
self.0.clear(); | |
} | |
} | |
impl SharedState { | |
// other methods | |
pub fn dispatch_events<'a>( | |
&'a mut self, | |
) -> WsResult<UpdateTick> { | |
let mut msg_buf: VecHolder<'a, 'a> = VecHolder::new(&mut self.msg_buf); | |
// push a bunch of messages | |
msg_buf.inner().push(/* messages */); | |
handle_msgs(msg_buf.inner())?; | |
Ok(self.latest_update) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment