From 74e9bbe6811deb4888bf0c20157506ab06e4f957 Mon Sep 17 00:00:00 2001 From: Viktor Sonesten Date: Sat, 20 Nov 2021 00:05:42 +0100 Subject: scb: derive serde, Hash, PartialOrd for VectActive behind gates Exposes two new feature gates for VectActive serde::{Serialize, Deserialize} (via "serde") and Hash, PartialOrd (via "std-map") for use on host-side ITM tracing programs. While the struct itself is not received directly over ITM, its use greatly simplifies the implementation by allowing VectActive as keys in map collections and file/socket {,de}serialization to forward the structure elsewhere. These features are not enabled by default. Before this patch, serde functionality could be realized via [0], but this does not propagate down a dependency chain (i.e. if realized for crate B, which crate A depends on, serde functionality is not exposed in crate A unless VectActive is wrapped in a type from crate B). I am not aware of any method to realize PartialOrd, Hash derivation for a downstream crate. [0] https://serde.rs/remote-derive.html --- xtask/src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'xtask/src/lib.rs') diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index a7b85e7..c3d8356 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -208,3 +208,24 @@ pub fn check_blobs() { println!("Blobs identical."); } + +// Check that serde and PartialOrd works with VectActive +pub fn check_host_side() { + use cortex_m::peripheral::scb::VectActive; + + // check serde + { + let v = VectActive::from(22).unwrap(); + let json = serde_json::to_string(&v).expect("Failed to serialize VectActive"); + let deser_v: VectActive = + serde_json::from_str(&json).expect("Failed to deserialize VectActive"); + assert_eq!(deser_v, v); + } + + // check PartialOrd + { + let a = VectActive::from(19).unwrap(); + let b = VectActive::from(20).unwrap(); + assert_eq!(a < b, true); + } +} -- cgit v1.2.3