wallet_adapter_common/
version.rs1use std::borrow::Cow;
2
3pub const WALLET_STANDARD_VERSION: &str = "1.0.0";
6
7#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub struct SemverVersion {
10 major: u8,
11 minor: u8,
12 patch: u8,
13}
14
15impl SemverVersion {
16 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn set_major(mut self, major: u8) -> Self {
23 self.major = major;
24
25 self
26 }
27 pub fn set_minor(mut self, minor: u8) -> Self {
29 self.minor = minor;
30
31 self
32 }
33
34 pub fn set_patch(mut self, patch: u8) -> Self {
36 self.patch = patch;
37
38 self
39 }
40
41 pub fn major(&self) -> u8 {
43 self.major
44 }
45
46 pub fn minor(&self) -> u8 {
48 self.minor
49 }
50
51 pub fn patch(&self) -> u8 {
53 self.patch
54 }
55
56 pub fn stringify_version<'a>(&'a self) -> Cow<'a, str> {
58 Cow::Borrowed("")
59 + Cow::Owned(self.major.to_string())
60 + "."
61 + Cow::Owned(self.minor.to_string())
62 + "."
63 + Cow::Owned(self.minor.to_string())
64 }
65}
66
67impl core::fmt::Debug for SemverVersion {
68 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69 write!(
70 f,
71 "SemverVersion({}.{}.{})",
72 self.major, self.minor, self.patch
73 )
74 }
75}
76
77impl core::fmt::Display for SemverVersion {
78 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
80 }
81}