Repo of no-std crates for my personal embedded projects

Switch to jiff for sachy-sntp

+41 -38
+32 -10
Cargo.lock
··· 121 121 checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" 122 122 123 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 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 + 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]] 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 + 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]] 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 - "chrono", 1262 1283 "defmt 1.0.1", 1263 1284 "embassy-net", 1264 1285 "embassy-time", 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 - chrono = { version = "0.4.41", default-features = false, optional = true } 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 - default = ["chrono", "embassy-net"] 24 - chrono = ["dep:chrono"] 23 + default = ["jiff", "embassy-net"] 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 - #[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> { 70 + #[cfg(feature = "jiff")] 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 - 129 - #[cfg(feature = "chrono")] 130 - pub fn as_naive_datetime(raw_time: SntpTimestamp) -> Result<chrono::NaiveDateTime, SntpError> { 131 - raw_time.try_into() 132 - } 133 123 } 134 124 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> { 125 + #[cfg(feature = "jiff")] 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 - chrono::DateTime::<chrono::Utc>::from_timestamp_micros(timestamp.utc_micros()) 150 - .ok_or(SntpError::InvalidTime) 130 + jiff::Timestamp::from_microsecond(timestamp.utc_micros()) 131 + .map_err(|_| SntpError::InvalidTime) 151 132 } 152 133 } 153 134