pub struct Server<Listener, Service> { /* private fields */ }
Expand description
A server.
The server listens for incoming connections and handles method calls using a service.
Implementations§
Source§impl<Listener, Service> Server<Listener, Service>
impl<Listener, Service> Server<Listener, Service>
Sourcepub fn new(listener: Listener, service: Service) -> Self
pub fn new(listener: Listener, service: Service) -> Self
Create a new server that serves service
to incomming connections from listener
.
Sourcepub async fn run(self) -> Result<()>
pub async fn run(self) -> Result<()>
Run the server.
§Caveats
Due to a bug in the rust compiler, the future returned by this method can not be
treated as Send
, even if all the specific types involved are Send
. A major consequence
of this fact unfortunately, is that it can not be spawned in a task of a multi-threaded
runtime. For example, you can not currently do tokio::spawn(server.run())
.
Fortunately, there are easy workarounds for this. You can either:
- Use a thread-local runtime (for example
tokio::runtime::LocalRuntime
ortokio::task::LocalSet
) to run the server in a local task, perhaps in a seprate thread. - Use some common API to run multiple futures at once, such as
futures::select!
ortokio::select!
.
Most importantly, this is most likely a temporary issue and will be fixed in the future. 😊
Trait Implementations§
Auto Trait Implementations§
impl<Listener, Service> Freeze for Server<Listener, Service>
impl<Listener, Service> RefUnwindSafe for Server<Listener, Service>where
Service: RefUnwindSafe,
Listener: RefUnwindSafe,
impl<Listener, Service> Send for Server<Listener, Service>
impl<Listener, Service> Sync for Server<Listener, Service>
impl<Listener, Service> Unpin for Server<Listener, Service>
impl<Listener, Service> UnwindSafe for Server<Listener, Service>where
Service: UnwindSafe,
Listener: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more