pub struct TheaterConnection {
pub address: SocketAddr,
/* private fields */
}Expand description
A client connection to a Theater server
This provides a thin wrapper around the TCP connection with simple send and receive methods that can be used with tokio::select!
Fields§
§address: SocketAddrServer address
Implementations§
Source§impl TheaterConnection
impl TheaterConnection
Sourcepub fn new(address: SocketAddr) -> Self
pub fn new(address: SocketAddr) -> Self
Sourcepub async fn connect(&mut self) -> Result<()>
pub async fn connect(&mut self) -> Result<()>
Connect to the Theater server
§Returns
Ok(())if the connection was successfulErr(...)if there was an error connecting
Sourcepub async fn send(&mut self, command: ManagementCommand) -> Result<()>
pub async fn send(&mut self, command: ManagementCommand) -> Result<()>
Sourcepub async fn receive(&mut self) -> Result<ManagementResponse>
pub async fn receive(&mut self) -> Result<ManagementResponse>
Receive a response from the server
This method will wait for the next response from the server. It can be used with tokio::select! to handle multiple operations.
§Returns
Ok(response)if a response was receivedErr(...)if there was an error receiving the response
pub async fn send_and_receive( &mut self, command: ManagementCommand, ) -> Result<ManagementResponse>
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if the connection is active
§Returns
trueif the connection is activefalseif the connection is not active
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TheaterConnection
impl RefUnwindSafe for TheaterConnection
impl Send for TheaterConnection
impl Sync for TheaterConnection
impl Unpin for TheaterConnection
impl UnsafeUnpin for TheaterConnection
impl UnwindSafe for TheaterConnection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more