From eabddf3019ce53bc526ccbc0be509bd13df2471f Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Sun, 12 Feb 2023 21:42:29 +0100 Subject: [PATCH] inline client functions --- kubi-udp/src/client.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kubi-udp/src/client.rs b/kubi-udp/src/client.rs index 07ab09c..7667e16 100644 --- a/kubi-udp/src/client.rs +++ b/kubi-udp/src/client.rs @@ -63,6 +63,7 @@ pub struct Client where S: Encode + Decode, R: Encode + Decode { _s: PhantomData, } impl Client where S: Encode + Decode, R: Encode + Decode { + #[inline] pub fn new(addr: SocketAddr, config: ClientConfig) -> Result { let bind_addr: SocketAddr = "0.0.0.0:0".parse().unwrap(); let socket = UdpSocket::bind(bind_addr)?; @@ -103,7 +104,7 @@ impl Client where S: Encode + Decode, R: Encode + Decode { self.timeout = Instant::now(); } - + #[inline] pub fn connect(&mut self) -> Result<()> { log::info!("client connect called"); if self.status != ClientStatus::Disconnected { @@ -117,6 +118,7 @@ impl Client where S: Encode + Decode, R: Encode + Decode { Ok(()) } + #[inline] pub fn disconnect(&mut self) -> Result<()> { if self.status != ClientStatus::Connected { bail!("Not Connected"); @@ -125,28 +127,34 @@ impl Client where S: Encode + Decode, R: Encode + Decode { Ok(()) } + #[inline] pub fn get_status(&self) -> ClientStatus { self.status } + #[inline] pub fn is_connected(&self) -> bool { self.status == ClientStatus::Connected } + #[inline] pub fn is_connecting(&self) -> bool { self.status == ClientStatus::Connecting } + #[inline] pub fn is_disconnected(&self) -> bool { self.status == ClientStatus::Disconnected } //Return true if the client has not made any connection attempts yet + #[inline] pub fn has_not_made_connection_attempts(&self) -> bool { matches!(self.status, ClientStatus::Disconnected) && matches!(self.disconnect_reason, DisconnectReason::NotConnected) } + #[inline] pub fn send_message(&self, message: S) -> Result<()> { if self.status != ClientStatus::Connected { bail!("Not Connected"); @@ -155,6 +163,7 @@ impl Client where S: Encode + Decode, R: Encode + Decode { Ok(()) } + #[inline] pub fn update(&mut self) -> Result<()> { // , callback: fn(ClientEvent) -> Result<()> if self.status == ClientStatus::Disconnected { return Ok(()) @@ -212,9 +221,12 @@ impl Client where S: Encode + Decode, R: Encode + Decode { Ok(()) } + #[inline] pub fn pop_event(&mut self) -> Option> { self.event_queue.pop_front() } + + #[inline] pub fn process_events(&mut self) -> DrainDeque> { self.event_queue.drain(..) }