[][src]Struct udp_netmsg::manager::UdpManager

pub struct UdpManager<T> where
    T: SerDesType
{ /* fields omitted */ }

Sends and receives datagrams conveniently. Runs a background thread to continuously check for datagrams without interrupting other functionality.

Implementations

impl<T> UdpManager<T> where
    T: SerDesType
[src]

pub fn get<J>(&self) -> Result<(SocketAddr, J), Error> where
    J: DeserializeOwned + 'static, 
[src]

Provides the oldest datagram of the specified type, if one exists.

Attempts to retrieve the serialized object from the underlying storage depending on the requested data type. The serialized object is removed (if one exists) from the underyling storage regardless of deserialization success. The deserialized object is returned to the user, if deserialization is successful

Errors

Returns error when the underlying storage is empty or the data could not be deserialized.

Panics

This will panic if the lock becomes poisioned.

pub fn get_all<J>(&self) -> Result<Vec<(SocketAddr, J)>, Error> where
    J: DeserializeOwned + 'static, 
[src]

Provides all datagrams of the specified type, if any exist.

Attempts to retrieve all serialized objects from the underlying storage depending on the requested data type. If storage for the object exists, it will attempt to deserialize any datagrams that exist. If deserialization fails, the datagram is lost. It will return an empty vector as long as the underlying storage existed. If use_ids is set to false, this will return only the datagrams that were able to be converted. All others are removed.

Errors

Returns an error when the underlying storage for that data type does not exist (different than being empty) or the data could not be deserialized

Panics

This will panic if the lock becomes poisioned.

pub fn peek<J>(&self) -> Result<(SocketAddr, J), Error> where
    J: DeserializeOwned + 'static, 
[src]

Provides the oldest datagram of the specified type, if one exists, without removing it from the underlying storage.

Attempts to retrieve the serialized object from the underlying storage depending on the requested data type. If a serialized object is available, a copy is taken and an attempt to deserialize the data is made. If successful, the deserialized object is returned to the user.

Errors

Returns error when the underlying storage is empty or the data could not be deserialized.

Panics

This will panic if the lock becomes poisioned.

pub fn remove_front<J>(&self) -> Result<(), Error> where
    J: DeserializeOwned + 'static, 
[src]

Removes the oldest datagram of the specified type, if one exists, without providing it to the user.

if use_ids is set false, it will remove the oldest datagram and the specified type is ignored.

Errors

Returns error when the underlying storage does not exist.

Panics

This will panic if the lock becomes poisioned.

pub fn remove_all<J>(&self) -> Result<(), Error> where
    J: DeserializeOwned + 'static, 
[src]

Removes all datagram of the specified type, if one exists, without providing it to the user.

if use_ids is set false, it will remove all datagram and the specified type is ignored.

Errors

Returns error when the underlying storage does not exist.

Panics

This will panic if the lock becomes poisioned.

pub fn send<J, A>(&self, datagram: J, dest_addr: A) -> Result<(), Error> where
    J: Serialize + 'static,
    A: ToSocketAddrs
[src]

Deserializes the datagram, appends the ID, and sends to requested location.

Consumes a datagram and a destination address for the datagram to be sent to. An attempt to serialize the data is made; If use_id is true, the datagram ID is prepended to the message. A request to the underlying UDP socket is then made to send the data.

Errors

Returns an error when the data could not be serialized or when the underyling UDP socket failed to send the message.

Panics

This will panic if the lock becomes poisioned.

pub fn set_id<F>(&self, id: u64) where
    F: 'static, 
[src]

Allows the header id of a particular struct to be specified rather than be automatically generated.

Generally, the struct ID is automatically created using a hash of the TypeID. This method allows the struct id to be set by the user. This should be called before any attempt to send or receive a datagram is made. This is commonly used if interacting with a socket that does not use this crate and is expecting a specific ID for the type of message you are sending.

Panics

This will panic if the lock becomes poisioned.

Trait Implementations

impl<T> Drop for UdpManager<T> where
    T: SerDesType
[src]

Allows the background thread to safely shutdown when the struct loses scope or program performs a shutdown.

Auto Trait Implementations

impl<T> !RefUnwindSafe for UdpManager<T>

impl<T> Send for UdpManager<T> where
    T: Send

impl<T> Sync for UdpManager<T> where
    T: Sync

impl<T> Unpin for UdpManager<T> where
    T: Unpin

impl<T> !UnwindSafe for UdpManager<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.