Skip to content

Commit 10f1802

Browse files
Add impls for uom_v0_37
1 parent fc47aec commit 10f1802

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

source/postcard-schema/Cargo.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ package = "serde-big-array"
7878
version = "0.5.1"
7979
optional = true
8080

81+
[dependencies.uom_v0_37]
82+
package = "uom"
83+
version = "0.37.0"
84+
optional = true
85+
default-features = false
86+
features = ["si", "serde"]
87+
8188
[dev-dependencies.postcard]
8289
path = "../postcard"
8390
version = "1.0"
@@ -89,8 +96,14 @@ version = "0.33.0"
8996
default-features = false
9097
features = ["serde-serialize-no-std"]
9198

99+
[dev-dependencies.uom_v0_37]
100+
package = "uom"
101+
version = "0.37.0"
102+
default-features = false
103+
features = ["si", "serde", "f32", "f64", "u8"]
104+
92105
[features]
93-
default = []
106+
default = ["uom-v0_37"]
94107
use-std = ["serde/std"]
95108
alloc = ["serde/alloc"]
96109
derive = ["postcard-derive"]
@@ -106,3 +119,4 @@ heapless-v0_8 = ["heapless_v0_8"]
106119
nalgebra-v0_33 = ["nalgebra_v0_33"]
107120
serde-big-array-v0_5 = ["serde-big-array_v0_5"]
108121
uuid-v1_0 = ["uuid_v1_0"]
122+
uom-v0_37 = ["uom_v0_37"]

source/postcard-schema/src/impls/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub mod serde_big_array_v0_5;
4545
#[cfg_attr(docsrs, doc(cfg(feature = "uuid-v1_0")))]
4646
pub mod uuid_v1_0;
4747

48+
#[cfg(feature = "uom-v0_37")]
49+
#[cfg_attr(docsrs, doc(cfg(feature = "uom-v0_37")))]
50+
pub mod uom_v0_37;
51+
4852
impl Schema for NamedType {
4953
const SCHEMA: &'static NamedType = &NamedType {
5054
name: "NamedType",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//! Implementations of the [`Schema`] trait for the `uom` crate v0.37
2+
3+
use crate::Schema;
4+
5+
impl<D, U, V> Schema
6+
for uom_v0_37::si::Quantity<D, U, V>
7+
where
8+
D: uom_v0_37::si::Dimension + ?Sized,
9+
U: uom_v0_37::si::Units<V> + ?Sized,
10+
V: uom_v0_37::num::Num + uom_v0_37::Conversion<V> + Schema,
11+
{
12+
const SCHEMA: &'static crate::schema::NamedType = V::SCHEMA;
13+
}
14+
15+
#[test]
16+
fn f32_schema_check() {
17+
type T = uom_v0_37::si::f32::Acceleration;
18+
assert_eq!(T::SCHEMA.ty, f32::SCHEMA.ty);
19+
}
20+
21+
#[test]
22+
fn f64_schema_check() {
23+
type T = uom_v0_37::si::f64::ThermodynamicTemperature;
24+
assert_eq!(T::SCHEMA.ty, f64::SCHEMA.ty);
25+
}
26+
27+
#[test]
28+
fn u8_schema_check() {
29+
type T = uom_v0_37::si::u8::AngularVelocity;
30+
assert_eq!(T::SCHEMA.ty, u8::SCHEMA.ty);
31+
}
32+
33+
#[test]
34+
fn u8_conversion() {
35+
let x = uom_v0_37::si::u8::Acceleration::new::<
36+
uom_v0_37::si::acceleration::meter_per_second_squared
37+
>(4);
38+
let y = postcard::to_stdvec(&x).unwrap();
39+
assert_eq!(Some(&4), y.first());
40+
}

0 commit comments

Comments
 (0)