pub enum ConnectionState<T> {
Disconnected,
Connected(T),
}Expand description
A backend state that is either disconnected or fully connected.
Buffer implementations use this helper when their reader or writer can be constructed before the peer endpoint exists, then filled in during connection setup.
Variants§
Disconnected
No backend has been connected yet.
Connected(T)
The backend is fully connected and ready to use.
Implementations§
Source§impl<T> ConnectionState<T>
impl<T> ConnectionState<T>
Sourcepub const fn disconnected() -> Self
pub const fn disconnected() -> Self
Create a disconnected backend state.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Whether the backend has been connected.
Sourcepub fn connected(&self) -> &T
pub fn connected(&self) -> &T
Get the connected backend, panicking if it is still disconnected.
Call this after validate() has proven the buffer is connected.
Sourcepub fn connected_mut(&mut self) -> &mut T
pub fn connected_mut(&mut self) -> &mut T
Get the connected backend mutably, panicking if it is still disconnected.
Call this after validate() has proven the buffer is connected.
Sourcepub fn set_connected(&mut self, value: T)
pub fn set_connected(&mut self, value: T)
Replace the state with a connected backend.
Sourcepub fn take_connected(&mut self) -> Option<T>
pub fn take_connected(&mut self) -> Option<T>
Take the connected backend out of the state.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ConnectionState<T>where
T: Freeze,
impl<T> RefUnwindSafe for ConnectionState<T>where
T: RefUnwindSafe,
impl<T> Send for ConnectionState<T>where
T: Send,
impl<T> Sync for ConnectionState<T>where
T: Sync,
impl<T> Unpin for ConnectionState<T>where
T: Unpin,
impl<T> UnsafeUnpin for ConnectionState<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for ConnectionState<T>where
T: UnwindSafe,
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