pub struct ServerBuilder<B, W = JsonCodec> {
config: ServerConfig,
byte_codec: B,
ws_codec: W,
executor: Option<Executor>,
}Expand description
Builder for constructing an RPC Server.
§Example
use std::sync::Arc;
use serde_json::Value;
use karyon_jsonrpc::{error::RPCError, rpc_impl, server::ServerBuilder};
struct Ping {}
#[rpc_impl]
impl Ping {
async fn ping(&self, _params: Value) -> Result<Value, RPCError> {
Ok(serde_json::json!("pong"))
}
}
async {
let server = ServerBuilder::new("tcp://127.0.0.1:60000")
.expect("create builder")
.service(Arc::new(Ping {}))
.build().await
.expect("build server");
server.start_block().await.expect("run server");
};Fields§
§config: ServerConfig§byte_codec: B§ws_codec: W§executor: Option<Executor>Implementations§
Source§impl<B, W> ServerBuilder<B, W>where
B: JsonRpcCodec,
W: WsCodec,
impl<B, W> ServerBuilder<B, W>where
B: JsonRpcCodec,
W: WsCodec,
Sourcepub fn service(self, service: Arc<dyn RPCService>) -> Self
pub fn service(self, service: Arc<dyn RPCService>) -> Self
Add an RPC service.
Sourcepub fn pubsub_service(self, service: Arc<dyn PubSubRPCService>) -> Self
pub fn pubsub_service(self, service: Arc<dyn PubSubRPCService>) -> Self
Add a PubSub RPC service.
Sourcepub fn tcp_config(self, config: TcpConfig) -> Result<Self>
pub fn tcp_config(self, config: TcpConfig) -> Result<Self>
Set TCP config.
Sourcepub fn tls_config(self, config: ServerTlsConfig) -> Result<Self>
pub fn tls_config(self, config: ServerTlsConfig) -> Result<Self>
Set TLS config.
Sourcepub fn quic_config(self, config: ServerQuicConfig) -> Result<Self>
pub fn quic_config(self, config: ServerQuicConfig) -> Result<Self>
Set QUIC config.
Sourcepub async fn with_executor(self, ex: Executor) -> Self
pub async fn with_executor(self, ex: Executor) -> Self
Set an executor.
Sourcepub fn with_notification_encoder(
self,
encoder: fn(NewNotification) -> Notification,
) -> Self
pub fn with_notification_encoder( self, encoder: fn(NewNotification) -> Notification, ) -> Self
Set a custom notification encoder.
Sourcepub fn with_ws_codec<W2: WsCodec>(self, ws_codec: W2) -> ServerBuilder<B, W2>
pub fn with_ws_codec<W2: WsCodec>(self, ws_codec: W2) -> ServerBuilder<B, W2>
Override the WebSocket codec. Only meaningful for ws:// /
wss:// endpoints.
Source§impl<B: JsonRpcCodec> ServerBuilder<B, JsonCodec>
impl<B: JsonRpcCodec> ServerBuilder<B, JsonCodec>
Sourcepub fn new_with_codec(
endpoint: impl ToEndpoint,
codec: B,
) -> Result<ServerBuilder<B, JsonCodec>>
pub fn new_with_codec( endpoint: impl ToEndpoint, codec: B, ) -> Result<ServerBuilder<B, JsonCodec>>
Create a builder with a custom byte-stream codec. The default
JsonCodec is used for ws:// / wss:// endpoints; override
with with_ws_codec.
Source§impl ServerBuilder<JsonCodec, JsonCodec>
impl ServerBuilder<JsonCodec, JsonCodec>
Sourcepub fn new(
endpoint: impl ToEndpoint,
) -> Result<ServerBuilder<JsonCodec, JsonCodec>>
pub fn new( endpoint: impl ToEndpoint, ) -> Result<ServerBuilder<JsonCodec, JsonCodec>>
Create a builder with the default JSON codec.
Auto Trait Implementations§
impl<B, W> Freeze for ServerBuilder<B, W>
impl<B, W = JsonCodec> !RefUnwindSafe for ServerBuilder<B, W>
impl<B, W> Send for ServerBuilder<B, W>
impl<B, W> Sync for ServerBuilder<B, W>
impl<B, W> Unpin for ServerBuilder<B, W>
impl<B, W> UnsafeUnpin for ServerBuilder<B, W>where
B: UnsafeUnpin,
W: UnsafeUnpin,
impl<B, W = JsonCodec> !UnwindSafe for ServerBuilder<B, W>
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