tangled
alpha
login
or
join now
sachy.dev
/
sachy-embed-core
0
fork
atom
Repo of no-std crates for my personal embedded projects
0
fork
atom
overview
issues
pulls
pipelines
Switch to jiff for sachy-sntp
sachy.dev
1 month ago
29d31456
c089bc6b
2/2
miri.yml
success
1min 11s
test.yml
success
55s
+41
-38
3 changed files
expand all
collapse all
unified
split
Cargo.lock
sachy-sntp
Cargo.toml
src
lib.rs
+32
-10
Cargo.lock
···
121
121
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
122
122
123
123
[[package]]
124
124
-
name = "chrono"
125
125
-
version = "0.4.42"
126
126
-
source = "registry+https://github.com/rust-lang/crates.io-index"
127
127
-
checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
128
128
-
dependencies = [
129
129
-
"num-traits",
130
130
-
]
131
131
-
132
132
-
[[package]]
133
124
name = "core-foundation"
134
125
version = "0.10.1"
135
126
source = "registry+https://github.com/rust-lang/crates.io-index"
···
665
656
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
666
657
667
658
[[package]]
659
659
+
name = "jiff"
660
660
+
version = "0.2.18"
661
661
+
source = "registry+https://github.com/rust-lang/crates.io-index"
662
662
+
checksum = "e67e8da4c49d6d9909fe03361f9b620f58898859f5c7aded68351e85e71ecf50"
663
663
+
dependencies = [
664
664
+
"jiff-static",
665
665
+
"portable-atomic",
666
666
+
"portable-atomic-util",
667
667
+
]
668
668
+
669
669
+
[[package]]
670
670
+
name = "jiff-static"
671
671
+
version = "0.2.18"
672
672
+
source = "registry+https://github.com/rust-lang/crates.io-index"
673
673
+
checksum = "e0c84ee7f197eca9a86c6fd6cb771e55eb991632f15f2bc3ca6ec838929e6e78"
674
674
+
dependencies = [
675
675
+
"proc-macro2",
676
676
+
"quote",
677
677
+
"syn",
678
678
+
]
679
679
+
680
680
+
[[package]]
668
681
name = "libc"
669
682
version = "0.2.179"
670
683
source = "registry+https://github.com/rust-lang/crates.io-index"
···
976
989
checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950"
977
990
978
991
[[package]]
992
992
+
name = "portable-atomic-util"
993
993
+
version = "0.2.4"
994
994
+
source = "registry+https://github.com/rust-lang/crates.io-index"
995
995
+
checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"
996
996
+
dependencies = [
997
997
+
"portable-atomic",
998
998
+
]
999
999
+
1000
1000
+
[[package]]
979
1001
name = "prettyplease"
980
1002
version = "0.2.37"
981
1003
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1258
1280
name = "sachy-sntp"
1259
1281
version = "0.1.0"
1260
1282
dependencies = [
1261
1261
-
"chrono",
1262
1283
"defmt 1.0.1",
1263
1284
"embassy-net",
1264
1285
"embassy-time",
1286
1286
+
"jiff",
1265
1287
"sachy-fmt",
1266
1288
]
1267
1289
+3
-3
sachy-sntp/Cargo.toml
···
8
8
rust-version.workspace = true
9
9
10
10
[dependencies]
11
11
-
chrono = { version = "0.4.41", default-features = false, optional = true }
11
11
+
jiff = { version = "0.2.18", default-features = false, optional = true }
12
12
defmt = { workspace = true, optional = true }
13
13
embassy-net = { workspace = true, features = [
14
14
"udp",
···
20
20
sachy-fmt = { path = "../sachy-fmt" }
21
21
22
22
[features]
23
23
-
default = ["chrono", "embassy-net"]
24
24
-
chrono = ["dep:chrono"]
23
23
+
default = ["jiff", "embassy-net"]
24
24
+
jiff = ["dep:jiff"]
25
25
embassy-net = ["dep:embassy-net", "dep:embassy-time"]
26
26
defmt = ["dep:defmt"]
+6
-25
sachy-sntp/src/lib.rs
···
67
67
ntp_epoch_micros + offset
68
68
}
69
69
70
70
-
#[cfg(feature = "chrono")]
71
71
-
pub fn try_to_utc(self) -> Result<chrono::DateTime<chrono::Utc>, SntpError> {
72
72
-
self.try_into()
73
73
-
}
74
74
-
75
75
-
#[cfg(feature = "chrono")]
76
76
-
pub fn try_to_naive_datetime(self) -> Result<chrono::NaiveDateTime, SntpError> {
70
70
+
#[cfg(feature = "jiff")]
71
71
+
pub fn try_to_unix_timestamp(self) -> Result<jiff::Timestamp, SntpError> {
77
72
self.try_into()
78
73
}
79
74
}
···
125
120
126
121
Err(SntpError::InvalidPacket)
127
122
}
128
128
-
129
129
-
#[cfg(feature = "chrono")]
130
130
-
pub fn as_naive_datetime(raw_time: SntpTimestamp) -> Result<chrono::NaiveDateTime, SntpError> {
131
131
-
raw_time.try_into()
132
132
-
}
133
123
}
134
124
135
135
-
#[cfg(feature = "chrono")]
136
136
-
impl TryFrom<SntpTimestamp> for chrono::NaiveDateTime {
137
137
-
type Error = SntpError;
138
138
-
139
139
-
fn try_from(timestamp: SntpTimestamp) -> Result<Self, Self::Error> {
140
140
-
Ok(chrono::DateTime::<chrono::Utc>::try_from(timestamp)?.naive_utc())
141
141
-
}
142
142
-
}
143
143
-
144
144
-
#[cfg(feature = "chrono")]
145
145
-
impl TryFrom<SntpTimestamp> for chrono::DateTime<chrono::Utc> {
125
125
+
#[cfg(feature = "jiff")]
126
126
+
impl TryFrom<SntpTimestamp> for jiff::Timestamp {
146
127
type Error = SntpError;
147
128
148
129
fn try_from(timestamp: SntpTimestamp) -> Result<Self, Self::Error> {
149
149
-
chrono::DateTime::<chrono::Utc>::from_timestamp_micros(timestamp.utc_micros())
150
150
-
.ok_or(SntpError::InvalidTime)
130
130
+
jiff::Timestamp::from_microsecond(timestamp.utc_micros())
131
131
+
.map_err(|_| SntpError::InvalidTime)
151
132
}
152
133
}
153
134