1use serde::{Deserialize, Serialize};
4
5pub mod v3;
6pub mod v4;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct VersionInfo {
11 pub api_version: String,
13 pub library_version: String,
15 pub server_version: String,
17}
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub enum ApiVersion {
22 V3,
23 V4,
24}
25
26impl ApiVersion {
27 pub fn as_str(&self) -> &str {
28 match self {
29 ApiVersion::V3 => "v3",
30 ApiVersion::V4 => "v4",
31 }
32 }
33
34 pub fn from_str_inner(s: &str) -> Option<Self> {
35 match s.to_lowercase().as_str() {
36 "v3" | "3" => Some(ApiVersion::V3),
37 "v4" | "4" => Some(ApiVersion::V4),
38 _ => None,
39 }
40 }
41}
42
43impl std::str::FromStr for ApiVersion {
44 type Err = String;
45
46 fn from_str(s: &str) -> Result<Self, Self::Err> {
47 Self::from_str_inner(s).ok_or_else(|| format!("Invalid API version: {}", s))
48 }
49}
50
51impl std::fmt::Display for ApiVersion {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 write!(f, "{}", self.as_str())
54 }
55}