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