Struct toy_rpc::server::ServerBuilder[][src]

pub struct ServerBuilder { /* fields omitted */ }

Implementations

impl ServerBuilder[src]

pub fn new() -> Self[src]

Creates a new ServerBuilder

pub fn register<S>(self, service: Arc<S>) -> Self where
    S: RegisterService + Send + Sync + 'static, 
[src]

Registers a new service to the Server

Example

use async_std::net::TcpListener;
use async_std::sync::Arc;
use toy_rpc_macros::{export_impl, service};
use toy_rpc::server::Server;

struct EchoService { }

#[export_impl]
impl EchoService {
    #[export_method]
    async fn echo(&self, req: String) -> Result<String, String> {
        Ok(req)
    }
}

#[async_std::main]
async fn main() {
    let addr = "127.0.0.1:8080";
     
    let echo_service = Arc::new(EchoService { });
    let server = Server::builder()
        .register(echo_service)
        .build();
     
    let listener = TcpListener::bind(addr).await.unwrap();

    let handle = task::spawn(async move {
        server.accept(listener).await.unwrap();
    });

    handle.await;
}

pub fn build(self) -> Server[src]

Creates an RPC Server

Trait Implementations

impl Default for ServerBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,