pub trait Runtime:
Send
+ Sync
+ 'static {
type Socket: AsyncUdpSocket;
type Executor: Executor;
// Required methods
fn executor(&self) -> &Self::Executor;
fn bind<'life0, 'async_trait>(
&'life0 self,
addr: SocketAddr,
) -> Pin<Box<dyn Future<Output = Result<Self::Socket>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
A trait defining the asynchronous execution and networking environment.
This trait abstracts over different async runtimes (e.g., Tokio, Smol), allowing the server logic to remain independent of the underlying event loop.
Implementers must ensure that both the socket and executor types are compatible with the chosen async reactor.
Required Associated Types§
Sourcetype Socket: AsyncUdpSocket
type Socket: AsyncUdpSocket
The asynchronous UDP socket type associated with this runtime.
Required Methods§
Sourcefn executor(&self) -> &Self::Executor
fn executor(&self) -> &Self::Executor
Returns a reference to the runtime’s task executor.
This is used by the server to spawn concurrent packet-handling tasks.
Sourcefn bind<'life0, 'async_trait>(
&'life0 self,
addr: SocketAddr,
) -> Pin<Box<dyn Future<Output = Result<Self::Socket>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn bind<'life0, 'async_trait>(
&'life0 self,
addr: SocketAddr,
) -> Pin<Box<dyn Future<Output = Result<Self::Socket>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Binds a new asynchronous UDP socket to the specified address.
§Errors
Returns an std::io::Result if the socket cannot be bound,
typically due to the address being in use or invalid permissions.