Skip to main content

Server

Struct Server 

Source
pub struct Server<T: XvcServer> { /* private fields */ }

Implementations§

Source§

impl<T: XvcServer> Server<T>

Source

pub fn new(server: T, config: Config) -> Server<T>

Create a new server wrapping server with the given config.

Source

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.

Source

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§

Source§

impl<T: Debug + XvcServer> Debug for Server<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.