MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / deserialize

Function deserialize

serde-duration/src/lib.rs:27–54  ·  view source on GitHub ↗
(deserializer: D)

Source from the content-addressed store, hash-verified

25}
26
27pub fn deserialize<'de, D>(deserializer: D) -> Result<Duration, D::Error>
28where
29 D: Deserializer<'de>,
30{
31 let s = String::deserialize(deserializer)?;
32 if s.is_empty() {
33 return Err(serde::de::Error::custom("Duration string cannot be empty"));
34 }
35 if s == "never" {
36 return Ok(Duration::MAX);
37 }
38 let (value, unit) = s.split_at(s.len() - 1);
39 let value = value.parse::<u64>().map_err(serde::de::Error::custom)?;
40
41 let seconds = match unit {
42 "s" => value,
43 "m" => value * 60,
44 "h" => value * 3600,
45 "d" => value * 24 * 3600,
46 _ => {
47 return Err(serde::de::Error::custom(
48 "Invalid time unit. Use s, m, h, or d",
49 ))
50 }
51 };
52
53 Ok(Duration::from_secs(seconds))
54}

Callers

nothing calls this directly

Calls 2

is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected