pub trait GenServer:
Send
+ Sized
+ Clone {
type CallMsg: Clone + Send + Sized + Sync;
type CastMsg: Clone + Send + Sized + Sync;
type OutMsg: Send + Sized;
type Error: Debug + Send;
// Provided methods
fn start(self) -> GenServerHandle<Self> { ... }
fn start_blocking(self) -> GenServerHandle<Self> { ... }
fn run(
self,
handle: &GenServerHandle<Self>,
rx: &mut Receiver<GenServerInMsg<Self>>,
) -> impl Future<Output = Result<(), GenServerError>> + Send { ... }
fn init(
self,
_handle: &GenServerHandle<Self>,
) -> impl Future<Output = Result<Self, Self::Error>> + Send { ... }
fn main_loop(
self,
handle: &GenServerHandle<Self>,
rx: &mut Receiver<GenServerInMsg<Self>>,
) -> impl Future<Output = Result<Self, GenServerError>> + Send { ... }
fn receive(
self,
handle: &GenServerHandle<Self>,
rx: &mut Receiver<GenServerInMsg<Self>>,
) -> impl Future<Output = Result<(Self, bool), GenServerError>> + Send { ... }
fn handle_call(
self,
_message: Self::CallMsg,
_handle: &GenServerHandle<Self>,
) -> impl Future<Output = CallResponse<Self>> + Send { ... }
fn handle_cast(
self,
_message: Self::CastMsg,
_handle: &GenServerHandle<Self>,
) -> impl Future<Output = CastResponse<Self>> + Send { ... }
fn teardown(
self,
_handle: &GenServerHandle<Self>,
) -> impl Future<Output = Result<(), Self::Error>> + Send { ... }
}Required Associated Types§
type CallMsg: Clone + Send + Sized + Sync
type CastMsg: Clone + Send + Sized + Sync
type OutMsg: Send + Sized
type Error: Debug + Send
Provided Methods§
fn start(self) -> GenServerHandle<Self>
Sourcefn start_blocking(self) -> GenServerHandle<Self>
fn start_blocking(self) -> GenServerHandle<Self>
Tokio tasks depend on a coolaborative multitasking model. “work stealing” can’t happen if the task is blocking the thread. As such, for sync compute task or other blocking tasks need to be in their own separate thread, and the OS will manage them through hardware interrupts. Start blocking provides such thread.
fn run( self, handle: &GenServerHandle<Self>, rx: &mut Receiver<GenServerInMsg<Self>>, ) -> impl Future<Output = Result<(), GenServerError>> + Send
Sourcefn init(
self,
_handle: &GenServerHandle<Self>,
) -> impl Future<Output = Result<Self, Self::Error>> + Send
fn init( self, _handle: &GenServerHandle<Self>, ) -> impl Future<Output = Result<Self, Self::Error>> + Send
Initialization function. It’s called before main loop. It can be overrided on implementations in case initial steps are required.
fn main_loop( self, handle: &GenServerHandle<Self>, rx: &mut Receiver<GenServerInMsg<Self>>, ) -> impl Future<Output = Result<Self, GenServerError>> + Send
fn receive( self, handle: &GenServerHandle<Self>, rx: &mut Receiver<GenServerInMsg<Self>>, ) -> impl Future<Output = Result<(Self, bool), GenServerError>> + Send
fn handle_call( self, _message: Self::CallMsg, _handle: &GenServerHandle<Self>, ) -> impl Future<Output = CallResponse<Self>> + Send
fn handle_cast( self, _message: Self::CastMsg, _handle: &GenServerHandle<Self>, ) -> impl Future<Output = CastResponse<Self>> + Send
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.