diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index db616cb..425e278 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -31,7 +31,11 @@ jobs: run: cargo clippy --features client,camera - name: Build client+telescope run: cargo clippy --features client,telescope + - name: Build client+focuser + run: cargo clippy --features client,focuser - name: Build server+camera run: cargo clippy --features server,camera - name: Build server+telescope run: cargo clippy --features server,telescope + - name: Build server+focuser + run: cargo clippy --features server,focuser diff --git a/Cargo.toml b/Cargo.toml index e93946a..a7cbcf4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0" async-fn-stream = "0.2.2" async-trait = "0.1.81" axum = { version = "0.7.5", optional = true } -bytemuck = { version = "1.17.0", features = ["derive", "extern_crate_std"], optional = true } +bytemuck = { version = "1.17.0", features = ["derive", "extern_crate_std"] } bytes = { version = "1.7.1", optional = true } custom_debug = "0.6.1" default-net = "0.22.0" @@ -38,7 +38,7 @@ serde_plain = "1.0.2" serde_repr = "0.1.19" socket2 = "0.5.7" thiserror = "1.0.63" -time = { version = "0.3.36", features = ["formatting", "parsing"] } +time = { version = "0.3.36", features = ["formatting", "parsing"], optional = true } tokio = { version = "1.39.3", features = ["net", "rt", "io-util"] } tracing = "0.1.40" tracing-futures = { version = "0.2.5", features = ["futures-03"] } @@ -54,11 +54,9 @@ ctor = "0.2.8" eframe = "0.28.1" # apparently Cargo doesn't allow `test` to enable `ndarray/rayon` when `ndarray` is an optional dependency # hence the duplicate dep with rayon feature -ndarray = { version = "0.16.1", features = ["rayon"] } nokhwa = { version = "0.10.4", features = ["input-native", "output-threaded"] } parking_lot = { version = "0.12.3", features = ["arc_lock", "send_guard"] } serial_test = "3.1.1" -time = { version = "0.3.36", features = ["formatting"] } tracing-subscriber = "0.3.18" tracing-error = "0.2.0" color-eyre = "0.6.3" @@ -71,7 +69,7 @@ harness = false [features] all-devices = ["camera", "covercalibrator", "dome", "filterwheel", "focuser", "observingconditions", "rotator", "safetymonitor", "switch", "telescope"] -camera = ["dep:mediatype", "dep:bytemuck", "dep:ndarray", "dep:serde-ndim"] +camera = ["dep:mediatype", "dep:ndarray", "dep:serde-ndim", "dep:time"] covercalibrator = [] dome = [] filterwheel = [] @@ -80,12 +78,12 @@ observingconditions = [] rotator = [] safetymonitor = [] switch = [] -telescope = [] +telescope = ["dep:time"] -client = ["dep:reqwest", "dep:bytes", "dep:mime", "dep:rand", "dep:once_cell"] -server = ["dep:axum", "dep:sailfish", "tokio/macros"] +client = ["dep:reqwest", "dep:bytes", "dep:mime", "dep:rand", "dep:once_cell", "time/parsing"] +server = ["dep:axum", "dep:sailfish", "tokio/macros", "time/formatting"] -test = ["client", "server", "camera", "tokio/macros", "tokio/rt-multi-thread"] +test = ["client", "server", "camera", "tokio/macros", "tokio/rt-multi-thread", "ndarray/rayon"] nightly = [] diff --git a/src/api/autogen/index.ts b/src/api/autogen/index.ts index 3ce571c..eecd6f8 100644 --- a/src/api/autogen/index.ts +++ b/src/api/autogen/index.ts @@ -207,7 +207,7 @@ interface EnumType extends RegisteredTypeBase { interface DateType extends RegisteredTypeBase { kind: 'Date'; - trailingZ: boolean; + formatName: string; } interface DeviceMethod { @@ -325,7 +325,8 @@ function handleType( name, doc: getDoc(schema), kind: 'Date', - trailingZ: schema.format === 'date-time' + formatName: + schema.format === 'date-time' ? 'DATE_TIME_OFFSET' : 'DATE_TIME' })); return rusty('std::time::SystemTime', `${formatter}`); } @@ -668,7 +669,6 @@ use macro_rules_attribute::apply; use num_enum::{IntoPrimitive, TryFromPrimitive}; use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; -use time::format_description::well_known::Iso8601; pub use server_info::*; @@ -745,7 +745,7 @@ ${stringifyIter(types, ({ features, type }) => { `; } case 'Date': { - let format = `Iso8601::DATE_TIME${type.trailingZ ? '_OFFSET' : ''}`; + let format = `&time::format_description::well_known::Iso8601::${type.formatName}`; return ` ${stringifyDoc(type.doc)} @@ -775,7 +775,7 @@ ${stringifyIter(types, ({ features, type }) => { fn serialize(value: &time::OffsetDateTime, serializer: S) -> Result { value .to_offset(time::UtcOffset::UTC) - .format(&${format}) + .format(${format}) .map_err(serde::ser::Error::custom)? .serialize(serializer) } @@ -791,10 +791,8 @@ ${stringifyIter(types, ({ features, type }) => { } fn visit_str(self, value: &str) -> Result { - match time::PrimitiveDateTime::parse(value, &${format}) { - Ok(time) => Ok(time.assume_utc()), - Err(err) => Err(serde::de::Error::custom(err)), - } + time::OffsetDateTime::parse(value, ${format}) + .map_err(serde::de::Error::custom) } } diff --git a/src/api/mod.rs b/src/api/mod.rs index abc8b23..f5db3d3 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -55,7 +55,6 @@ use macro_rules_attribute::apply; use num_enum::{IntoPrimitive, TryFromPrimitive}; use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; -use time::format_description::well_known::Iso8601; pub use server_info::*; @@ -133,7 +132,7 @@ impl LastExposureStartTime { ) -> Result { value .to_offset(time::UtcOffset::UTC) - .format(&Iso8601::DATE_TIME) + .format(&time::format_description::well_known::Iso8601::DATE_TIME) .map_err(serde::ser::Error::custom)? .serialize(serializer) } @@ -151,10 +150,11 @@ impl LastExposureStartTime { } fn visit_str(self, value: &str) -> Result { - match time::PrimitiveDateTime::parse(value, &Iso8601::DATE_TIME) { - Ok(time) => Ok(time.assume_utc()), - Err(err) => Err(serde::de::Error::custom(err)), - } + time::OffsetDateTime::parse( + value, + &time::format_description::well_known::Iso8601::DATE_TIME, + ) + .map_err(serde::de::Error::custom) } } @@ -478,7 +478,7 @@ impl TelescopeUtcdate { ) -> Result { value .to_offset(time::UtcOffset::UTC) - .format(&Iso8601::DATE_TIME_OFFSET) + .format(&time::format_description::well_known::Iso8601::DATE_TIME_OFFSET) .map_err(serde::ser::Error::custom)? .serialize(serializer) } @@ -496,10 +496,11 @@ impl TelescopeUtcdate { } fn visit_str(self, value: &str) -> Result { - match time::PrimitiveDateTime::parse(value, &Iso8601::DATE_TIME_OFFSET) { - Ok(time) => Ok(time.assume_utc()), - Err(err) => Err(serde::de::Error::custom(err)), - } + time::OffsetDateTime::parse( + value, + &time::format_description::well_known::Iso8601::DATE_TIME_OFFSET, + ) + .map_err(serde::de::Error::custom) } }