From 5111a3d5749625c3d8e26a24a5a32c4da58f18d3 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Thu, 30 Nov 2023 23:51:18 +0300 Subject: net: Use ToConn and ToListener traits for objects that can be converted to Conn and Listener. --- jsonrpc/src/client.rs | 6 +++--- jsonrpc/src/lib.rs | 4 ++-- jsonrpc/src/server.rs | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'jsonrpc/src') diff --git a/jsonrpc/src/client.rs b/jsonrpc/src/client.rs index 0061002..69c2e6d 100644 --- a/jsonrpc/src/client.rs +++ b/jsonrpc/src/client.rs @@ -2,7 +2,7 @@ use log::debug; use serde::{de::DeserializeOwned, Serialize}; use karyons_core::util::random_32; -use karyons_net::Conn; +use karyons_net::ToConn; use crate::{ codec::{Codec, CodecConfig}, @@ -23,12 +23,12 @@ pub struct Client { impl Client { /// Creates a new RPC client by passing a Tcp, Unix, or Tls connection. - pub fn new(conn: Conn, config: ClientConfig) -> Self { + pub fn new(conn: C, config: ClientConfig) -> Self { let codec_config = CodecConfig { max_allowed_buffer_size: 0, ..Default::default() }; - let codec = Codec::new(conn, codec_config); + let codec = Codec::new(conn.to_conn(), codec_config); Self { codec, config } } diff --git a/jsonrpc/src/lib.rs b/jsonrpc/src/lib.rs index 65fb38f..da9047d 100644 --- a/jsonrpc/src/lib.rs +++ b/jsonrpc/src/lib.rs @@ -27,7 +27,7 @@ //! // Creates a new server //! let listener = TcpListener::bind("127.0.0.1:60000").await.unwrap(); //! let config = ServerConfig::default(); -//! let server = Server::new(listener.into(), config, ex.clone()); +//! let server = Server::new(listener, config, ex.clone()); //! //! // Register the HelloWorld service //! register_service!(HelloWorld, say_hello); @@ -43,7 +43,7 @@ //! // Creates a new client //! let conn = TcpStream::connect("127.0.0.1:60000").await.unwrap(); //! let config = ClientConfig::default(); -//! let client = Client::new(conn.into(), config); +//! let client = Client::new(conn, config); //! //! let result: String = client.call("HelloWorld.say_hello", "world".to_string()).await.unwrap(); //! }; diff --git a/jsonrpc/src/server.rs b/jsonrpc/src/server.rs index 44de336..4f1bada 100644 --- a/jsonrpc/src/server.rs +++ b/jsonrpc/src/server.rs @@ -8,7 +8,7 @@ use karyons_core::{ Executor, }; -use karyons_net::{Conn, Listener}; +use karyons_net::{Conn, Listener, ToListener}; use crate::{ codec::{Codec, CodecConfig}, @@ -33,9 +33,9 @@ pub struct Server<'a> { impl<'a> Server<'a> { /// Creates a new RPC server by passing a listener. It supports Tcp, Unix, and Tls. - pub fn new(listener: Listener, config: ServerConfig, ex: Executor<'a>) -> Arc { + pub fn new(listener: T, config: ServerConfig, ex: Executor<'a>) -> Arc { Arc::new(Self { - listener, + listener: listener.to_listener(), services: RwLock::new(HashMap::new()), task_group: TaskGroup::new(ex), config, -- cgit v1.2.3