Skip to main content

trillium_channels/
version.rs

1use std::{convert::Infallible, str::FromStr};
2
3/**
4The phoenix channel "protocol" version
5*/
6#[derive(Debug, Clone, Copy)]
7#[non_exhaustive]
8pub enum Version {
9    /// the implicit first version of the protocol
10    V1,
11
12    /// version 2.x of the protocol
13    V2,
14}
15
16impl Default for Version {
17    fn default() -> Self {
18        Self::V1
19    }
20}
21
22impl FromStr for Version {
23    type Err = Infallible;
24
25    fn from_str(s: &str) -> Result<Self, Self::Err> {
26        match s.chars().next() {
27            Some('2') => Ok(Self::V2),
28            _ => Ok(Self::V1),
29        }
30    }
31}
32
33impl From<&str> for Version {
34    fn from(s: &str) -> Self {
35        s.parse().unwrap()
36    }
37}