Struct mles_utils::MsgConn

source ·
pub struct MsgConn { /* private fields */ }
Expand description

Msg connection structure

This structure defines the Mles connection for simple synchronous connections.

Implementations§

source§

impl MsgConn

source

pub fn new(uid: String, channel: String) -> MsgConn

Create a new MsgConn object for a connection.

Example
use mles_utils::MsgConn;

let conn = MsgConn::new("My uid".to_string(), "My channel".to_string());
source

pub fn get_uid(&self) -> String

Gets the defined uid.

Example
use mles_utils::MsgConn;

let conn = MsgConn::new("My uid".to_string(), "My channel".to_string());
assert_eq!("My uid".to_string(), conn.get_uid());
source

pub fn get_channel(&self) -> String

Gets the defined channel.

Example
use mles_utils::MsgConn;

let conn = MsgConn::new("My uid".to_string(), "My channel".to_string());
assert_eq!("My channel".to_string(), conn.get_channel());
source

pub fn get_key(&self) -> Option<u64>

Gets the defined key.

Example
use mles_utils::MsgConn;

//key is set only when connection is initiated..
let conn = MsgConn::new("My uid".to_string(), "My channel".to_string());
assert_eq!(true, conn.get_key().is_none());
source

pub fn connect_with_message(self, raddr: SocketAddr, msg: Vec<u8>) -> MsgConn

Connects to the defined address with a message.

source

pub fn connect(self, raddr: SocketAddr) -> MsgConn

Connects to the defined address (without a message).

source

pub fn send_message(self, msg: Vec<u8>) -> MsgConn

Send a message. Blocks until a message is sent.

Errors

If a message cannot be sent, stream is set to None.

source

pub fn read_message(self) -> (MsgConn, Vec<u8>)

Reads a message with non-zero message content. Blocks until a message is received.

Errors

If message cannot be read, an empty message is returned.

source

pub fn close(self) -> MsgConn

Closes the connection.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.