NetrexMC / RakNet

RakNet implementation in Rust
Apache License 2.0
44 stars 12 forks source link

`RakNetServer::start` disallows mutation through the event function. #16

Closed john-bv closed 2 years ago

john-bv commented 2 years ago

Here I will be discussing possible solutions on a discussion with this issue linked. For more information on why this is an issue, reference this issue.

john-bv commented 2 years ago

Functional Approach

This approach is quite simple and straight to the point. We would pass the raknet instance directly into the function to allow the instance to outlive the threads.

How this might look:

pub fn start(server: &mut RakNetServer, event_cb: dyn FnMut(RakNetEvent) -> Option<RakResult> + Send + Sync) -> JoinHandles {
    // This should allow us to mutate the server inside the event callback using crossbeam.
    // spawn threads...
}