Struct Networker

Source
pub struct Networker<T: NetworkContent + 'static, E: HandlerError> { /* private fields */ }
Expand description

This struct is the main API for using netty. It allows the creation of a server and the ability to send messages to clients.

Implementations§

Source§

impl<T: NetworkContent, E: HandlerError> Networker<T, E>

Source

pub async fn new<H, M, FH, FM>( address: SocketAddr, directory_service: impl DirectoryService<String, E> + 'static, handle_handshakes: H, handle_messages: M, ) -> Result<Networker<T, E>, Error<E>>
where FM: Future<Output = Result<(), Error<E>>> + Send, FH: Future<Output = Result<String, Error<E>>> + Send, M: FnMut(NetworkMessage<T>, Connection<T, E>) -> FM + Send + Sync + Clone + 'static, H: FnMut(NetworkMessage<T>, Connection<T, E>) -> FH + Send + Sync + Clone + 'static,

Creates a new networker using. address is the network socket address that the server should listen to. directory_service is the directory service to use in order to translate IDs to addresses. handle_handshakes is a closure that is called when a new connection is recieved which sends a NetworkMessage. This closure should authenticate if appropriate and do other handshake and setup related things. handle_messages is a closure that is called for all messages received from a connection that has already been handshaked.

Source

pub async fn send_message( &self, message: NetworkMessage<T>, timeout: Option<Duration>, react: Option<Action<T, E>>, ) -> Result<(), Error<E>>

Sends a message and then reacts to the response with the action and then returns the last message returned

Source

pub async fn listen(&self, should_listen: bool) -> Result<(), Error<E>>

Starts the server

Trait Implementations§

Source§

impl<T: Clone + NetworkContent + 'static, E: Clone + HandlerError> Clone for Networker<T, E>

Source§

fn clone(&self) -> Networker<T, E>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + NetworkContent + 'static, E: Debug + HandlerError> Debug for Networker<T, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, E> Freeze for Networker<T, E>

§

impl<T, E> RefUnwindSafe for Networker<T, E>

§

impl<T, E> Send for Networker<T, E>

§

impl<T, E> Sync for Networker<T, E>

§

impl<T, E> Unpin for Networker<T, E>

§

impl<T, E> UnwindSafe for Networker<T, E>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> HandlerError for T
where T: Send + Sync + Debug + 'static + Clone,