diff --git a/CHANGELOG.md b/CHANGELOG.md index 2df28e9..348656a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ Procedure when bumping the version number: ## Unreleased +### Added +- `Status` conversion utility methods + ## v0.2.0 - 2022-12-10 ### Added diff --git a/src/conn.rs b/src/conn.rs index 0f48779..7ee0fd0 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -216,6 +216,36 @@ pub enum Status { Joined(Joined), } +impl Status { + pub fn into_joining(self) -> Option { + match self { + Self::Joining(joining) => Some(joining), + Self::Joined(_) => None, + } + } + + pub fn into_joined(self) -> Option { + match self { + Self::Joining(_) => None, + Self::Joined(joined) => Some(joined), + } + } + + pub fn joining(&self) -> Option<&Joining> { + match self { + Self::Joining(joining) => Some(joining), + Self::Joined(_) => None, + } + } + + pub fn joined(&self) -> Option<&Joined> { + match self { + Self::Joining(_) => None, + Self::Joined(joined) => Some(joined), + } + } +} + struct State { ws_tx: SplitSink, last_id: usize,