Skip to main content

trillium_channels/
version.rs

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