tangled
alpha
login
or
join now
vielle.dev
/
wol
1
fork
atom
[WIP] A simple wake-on-lan service
1
fork
atom
overview
issues
pulls
pipelines
refactor deserializer helpers
vielle.dev
6 days ago
68f41167
10d5f51f
verified
This commit was signed with the committer's
known signature
.
vielle.dev
SSH Key Fingerprint:
SHA256:EoUuRRBFQKUfYh74C568g83i9g4fVi5OTtOENMSfa+0=
+37
-33
4 changed files
expand all
collapse all
unified
split
src
config.rs
server
ping.rs
wake.rs
utils.rs
+4
-5
src/config.rs
···
3
3
collections::{HashMap, HashSet},
4
4
fs::File,
5
5
io::Read,
6
6
+
net::IpAddr,
6
7
path::PathBuf,
7
8
};
8
9
use thiserror::Error;
···
34
35
35
36
#[derive(Deserialize, Serialize, Debug, Clone)]
36
37
pub struct Target {
37
37
-
#[serde(
38
38
-
deserialize_with = "crate::utils::deserialize_mac",
39
39
-
serialize_with = "crate::utils::serialize_mac"
40
40
-
)]
38
38
+
#[serde(with = "crate::utils::mac")]
41
39
pub mac: crate::mac::MacAddress,
42
42
-
pub ip: Option<String>,
40
40
+
#[serde(default, with = "crate::utils::ip::option")]
41
41
+
pub ip: Option<IpAddr>,
43
42
pub url: Option<String>,
44
43
}
45
44
+1
-1
src/server/ping.rs
···
5
5
6
6
#[derive(Deserialize)]
7
7
pub struct PingRequest {
8
8
-
#[serde(deserialize_with = "crate::utils::deserialize_ip")]
8
8
+
#[serde(with = "crate::utils::ip")]
9
9
ip: IpAddr,
10
10
}
11
11
+1
-1
src/server/wake.rs
···
5
5
6
6
#[derive(Deserialize)]
7
7
pub struct WakeRequest {
8
8
-
#[serde(deserialize_with = "crate::utils::deserialize_mac")]
8
8
+
#[serde(with = "crate::utils::mac")]
9
9
mac: MacAddress,
10
10
}
11
11
+31
-26
src/utils.rs
···
1
1
-
use std::{net::IpAddr, str::FromStr};
1
1
+
pub mod ip {
2
2
+
use serde::{Deserialize, Deserializer, Serializer, de::Error};
3
3
+
use std::{net::IpAddr, str::FromStr};
2
4
3
3
-
use serde::{Deserialize, Deserializer, Serializer, de::Error};
5
5
+
pub fn deserialize<'de, D>(de: D) -> Result<IpAddr, D::Error>
6
6
+
where
7
7
+
D: Deserializer<'de>,
8
8
+
{
9
9
+
IpAddr::from_str(&String::deserialize(de)?).map_err(Error::custom)
10
10
+
}
4
11
5
5
-
use crate::mac::MacAddress;
6
6
-
7
7
-
pub fn deserialize_ip<'de, D>(de: D) -> Result<IpAddr, D::Error>
8
8
-
where
9
9
-
D: Deserializer<'de>,
10
10
-
{
11
11
-
IpAddr::from_str(&String::deserialize(de)?).map_err(Error::custom)
12
12
+
pub fn serialize<S>(ip: &IpAddr, se: S) -> Result<S::Ok, S::Error>
13
13
+
where
14
14
+
S: Serializer,
15
15
+
{
16
16
+
se.serialize_str(ip.to_string().as_str())
17
17
+
}
12
18
}
13
19
14
14
-
pub fn serialize_ip<S>(ip: &IpAddr, se: S) -> Result<S::Ok, S::Error>
15
15
-
where
16
16
-
S: Serializer,
17
17
-
{
18
18
-
se.serialize_str(ip.to_string().as_str())
19
19
-
}
20
20
+
pub mod mac {
21
21
+
use crate::mac::MacAddress;
22
22
+
use serde::{Deserialize, Deserializer, Serializer, de::Error};
23
23
+
use std::str::FromStr;
20
24
21
21
-
pub fn deserialize_mac<'de, D>(de: D) -> Result<MacAddress, D::Error>
22
22
-
where
23
23
-
D: Deserializer<'de>,
24
24
-
{
25
25
-
MacAddress::from_str(&String::deserialize(de)?).map_err(Error::custom)
26
26
-
}
25
25
+
pub fn deserialize<'de, D>(de: D) -> Result<MacAddress, D::Error>
26
26
+
where
27
27
+
D: Deserializer<'de>,
28
28
+
{
29
29
+
MacAddress::from_str(&String::deserialize(de)?).map_err(Error::custom)
30
30
+
}
27
31
28
28
-
pub fn serialize_mac<S>(mac: &MacAddress, se: S) -> Result<S::Ok, S::Error>
29
29
-
where
30
30
-
S: Serializer,
31
31
-
{
32
32
-
se.serialize_str(&mac.to_string())
32
32
+
pub fn serialize<S>(mac: &MacAddress, se: S) -> Result<S::Ok, S::Error>
33
33
+
where
34
34
+
S: Serializer,
35
35
+
{
36
36
+
se.serialize_str(&mac.to_string())
37
37
+
}
33
38
}