1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#![allow(dead_code)]
#[cfg(feature = "clap")]
#[macro_use]
extern crate clap;
#[macro_use]
extern crate amplify;
#[macro_use]
extern crate amplify_derive;
#[cfg(feature = "async-trait")]
#[macro_use]
extern crate async_trait;
#[macro_use]
extern crate log;
#[macro_use]
extern crate num_derive;
#[cfg(feature = "serde")]
extern crate serde_crate as serde;
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde_with;
#[macro_use]
pub extern crate lnpbp;
#[macro_use]
pub extern crate lnpbp_derive;
#[macro_use]
pub extern crate diesel;
#[cfg(any(feature = "node", feature = "client"))]
pub mod api;
#[cfg(feature = "cli")]
pub mod cli;
pub mod constants;
pub mod error;
#[cfg(any(feature = "node"))]
pub mod i9n;
pub mod util;
#[cfg(any(feature = "node", feature = "client"))]
mod contracts;
#[cfg(any(feature = "node", feature = "client"))]
pub mod rgbd;
#[cfg(any(feature = "node", feature = "client"))]
pub mod service;
#[cfg(feature = "node")]
pub mod stash;
#[cfg(any(feature = "node", feature = "client"))]
pub use contracts::*;
use std::str::FromStr;
#[derive(
Clap,
Copy,
Clone,
PartialEq,
Eq,
Hash,
Debug,
Display,
FromPrimitive,
ToPrimitive,
)]
#[non_exhaustive]
pub enum DataFormat {
#[cfg(feature = "serde_json")]
#[display("json")]
Json,
#[cfg(feature = "serde_yaml")]
#[display("yaml")]
Yaml,
#[cfg(feature = "toml")]
#[display("toml")]
Toml,
#[display("strict-encode")]
StrictEncode,
}
impl_enum_strict_encoding!(DataFormat);
impl DataFormat {
pub fn extension(&self) -> &'static str {
match self {
#[cfg(feature = "serde_yaml")]
DataFormat::Yaml => "yaml",
#[cfg(feature = "serde_json")]
DataFormat::Json => "json",
#[cfg(feature = "toml")]
DataFormat::Toml => "toml",
DataFormat::StrictEncode => "se",
}
}
}
#[derive(Clone, PartialEq, Eq, Hash, Debug, Display, Error, From)]
#[display(doc_comments)]
pub enum FileFormatParseError {
UnknownFormat,
}
impl FromStr for DataFormat {
type Err = FileFormatParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match &s.to_lowercase() {
#[cfg(feature = "serde_yaml")]
s if s.starts_with("yaml") || s.starts_with("yml") => Self::Yaml,
#[cfg(feature = "serde_json")]
s if s.starts_with("json") => Self::Json,
#[cfg(feature = "toml")]
s if s.starts_with("toml") => Self::Toml,
s if s.starts_with("se")
|| s.starts_with("dat")
|| s.starts_with("strictencode")
|| s.starts_with("strict-encode")
|| s.starts_with("strict_encode") =>
{
Self::StrictEncode
}
_ => Err(FileFormatParseError::UnknownFormat)?,
})
}
}