pub struct Server<T: XvcServer> { /* private fields */ }Implementations§
Source§impl<T: XvcServer> Server<T>
impl<T: XvcServer> Server<T>
Sourcepub fn new(server: T, config: Config) -> Server<T>
pub fn new(server: T, config: Config) -> Server<T>
Create a new server wrapping server with the given config.
Sourcepub async fn listen(&self, addr: impl ToSocketAddrs) -> Result<()>where
T: Send + 'static,
pub async fn listen(&self, addr: impl ToSocketAddrs) -> Result<()>where
T: Send + 'static,
Bind to addr and serve clients until the process exits.
This is the standard production entry point. To shut the server down
programmatically (e.g. in tests), use listen_on
with a CancellationToken.
Sourcepub async fn listen_on(
&self,
listener: TcpListener,
shutdown: CancellationToken,
) -> Result<()>where
T: Send + 'static,
pub async fn listen_on(
&self,
listener: TcpListener,
shutdown: CancellationToken,
) -> Result<()>where
T: Send + 'static,
Serve clients from a pre-bound listener until shutdown is cancelled.
When shutdown is cancelled the accept loop exits cleanly; any connection
that is already being served runs to completion before the task finishes.
This entry point is useful when the caller needs to control the server lifetime programmatically — for example in tests, or to hook into a process-wide signal handler:
ⓘ
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?;
let addr = listener.local_addr()?;
let token = CancellationToken::new();
// Shut down on Ctrl+C
tokio::spawn({
let token = token.clone();
async move {
tokio::signal::ctrl_c().await.unwrap();
token.cancel();
}
});
server.listen_on(listener, token).await?;Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Server<T>
impl<T> !RefUnwindSafe for Server<T>
impl<T> Send for Server<T>where
T: Send,
impl<T> Sync for Server<T>where
T: Send,
impl<T> Unpin for Server<T>
impl<T> UnsafeUnpin for Server<T>
impl<T> !UnwindSafe for Server<T>
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