Struct abbegm::tokio_peer::EgmPeer
source · [−]pub struct EgmPeer { /* private fields */ }
Expand description
Asynchronous EGM peer capable of sending and receiving messages.
Implementations
sourceimpl EgmPeer
impl EgmPeer
sourcepub fn new(socket: UdpSocket) -> Self
pub fn new(socket: UdpSocket) -> Self
Wrap an existing UDP socket in a peer.
If you want to use the EgmPeer::recv
and EgmPeer::send
functions,
you should use an already connected socket.
Otherwise, you can only use EgmPeer::recv_from
and EgmPeer::send_to
.
sourcepub async fn bind(addrs: impl ToSocketAddrs) -> Result<Self>
pub async fn bind(addrs: impl ToSocketAddrs) -> Result<Self>
Create an EGM peer on a newly bound UDP socket.
The socket will not be connected to a remote peer,
so you can only use EgmPeer::recv_from
and EgmPeer::send_to
.
sourcepub fn bind_sync(addrs: impl ToSocketAddrs) -> Result<Self>
pub fn bind_sync(addrs: impl ToSocketAddrs) -> Result<Self>
Synchronously create an EGM peer on a newly bound UDP socket.
This function allows you to create the peer synchronously, but use an asynchronous API for communicating with the robot. This can be useful if you want to perform initialization of your application synchronously.
The socket will not be connected to a remote peer,
so you can only use EgmPeer::recv_from
and EgmPeer::send_to
.
sourcepub fn socket_mut(&mut self) -> &mut UdpSocket
pub fn socket_mut(&mut self) -> &mut UdpSocket
Get an exclusive reference to the inner socket.
sourcepub fn into_socket(self) -> UdpSocket
pub fn into_socket(self) -> UdpSocket
Consume self and get the inner socket.
sourcepub async fn recv(&self) -> Result<EgmRobot, ReceiveError>
pub async fn recv(&self) -> Result<EgmRobot, ReceiveError>
Receive a message from the remote address to which the inner socket is connected.
To use this function, you must pass an already connected socket to EgmPeer::new
.
If the peer was created with an unconnected socket, this function will panic.
sourcepub async fn recv_from(&self) -> Result<(EgmRobot, SocketAddr), ReceiveError>
pub async fn recv_from(&self) -> Result<(EgmRobot, SocketAddr), ReceiveError>
Receive a message from any remote address.
sourcepub fn purge_read_queue(&self) -> Result<()>
pub fn purge_read_queue(&self) -> Result<()>
Purge all messages from the socket read queue.
sourcepub async fn send(&mut self, msg: &EgmSensor) -> Result<(), SendError>
pub async fn send(&mut self, msg: &EgmSensor) -> Result<(), SendError>
Send a message to the remote address to which the inner socket is connected.
To use this function, you must pass an already connected socket to EgmPeer::new
.
If the peer was created with an unconnected socket, this function will panic.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for EgmPeer
impl Send for EgmPeer
impl Sync for EgmPeer
impl Unpin for EgmPeer
impl UnwindSafe for EgmPeer
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more