pub struct Server { /* private fields */ }Expand description
RPC server that listens for and handles incoming requests.
The Server manages the lifecycle of an RPC server, including:
- Service registration through a
Router - Network listening on specified addresses
- Connection management through socket pools
- Request dispatching to registered service implementations
§Examples
ⓘ
let mut router = Router::default();
EchoService::ruapc_export(Arc::new(DemoImpl), &mut router);
let server = Server::create(router, &SocketPoolConfig::default()).unwrap();
let server = Arc::new(server);
let addr = SocketAddr::from_str("127.0.0.1:8000").unwrap();
server.listen(addr).await.unwrap();
server.join().await;Implementations§
Source§impl Server
impl Server
Sourcepub fn create(router: Router, config: &SocketPoolConfig) -> Result<Self>
pub fn create(router: Router, config: &SocketPoolConfig) -> Result<Self>
Creates a new RPC server with the given router and configuration.
§Arguments
router- The router containing registered service methodsconfig- Socket pool configuration specifying transport protocol and options
§Errors
Returns an error if:
- Socket pool creation fails
- State initialization fails
§Examples
let router = Router::default();
let server = Server::create(router, &SocketPoolConfig::default()).unwrap();Sourcepub fn stop(&self)
pub fn stop(&self)
Stops the server, closing all listeners and connections.
This method initiates a graceful shutdown by:
- Stopping the listener from accepting new connections
- Stopping the socket pool to close existing connections
Call join after this to wait for shutdown to complete.
Sourcepub async fn join(&self)
pub async fn join(&self)
Waits for the server to fully shut down.
This method blocks until:
- All listeners have stopped accepting connections
- All socket pools have closed their connections
Should be called after stop.
Sourcepub async fn listen(&self, addr: SocketAddr) -> Result<SocketAddr>
pub async fn listen(&self, addr: SocketAddr) -> Result<SocketAddr>
Starts listening for incoming connections on the specified address.
§Arguments
addr- The socket address to bind to
§Returns
Returns the actual address the server is listening on, which may differ from the requested address if port 0 was specified.
§Errors
Returns an error if:
- The address cannot be bound
- The listener fails to start
§Examples
let addr = SocketAddr::from_str("127.0.0.1:8000").unwrap();
let listening_addr = server.listen(addr).await.unwrap();
println!("Server listening on {}", listening_addr);Auto Trait Implementations§
impl !RefUnwindSafe for Server
impl !UnwindSafe for Server
impl Freeze for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
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