Skip to content

Commit adbb20d

Browse files
committed
Update to unreleased postcard-schema traits and types.
1 parent 5d9a58d commit adbb20d

File tree

11 files changed

+310
-269
lines changed

11 files changed

+310
-269
lines changed

source/postcard-rpc-test/Cargo.lock

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/postcard-rpc-test/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ features = ["rt", "macros", "sync", "time"]
2626
[features]
2727
default = ["alpha"]
2828
alpha = []
29+
30+
[patch.crates-io.postcard-schema]
31+
git = "https://github.com/rslawson/postcard"
32+
features = ["derive"]

source/postcard-rpc-test/tests/basic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::{
44
};
55
use std::{sync::Arc, time::Instant};
66

7-
use postcard_schema::{schema::owned::OwnedNamedType, Schema};
7+
use postcard_schema::{schema::owned::OwnedDataModelType, Schema};
88
use serde::{Deserialize, Serialize};
99
use tokio::{sync::mpsc, task::yield_now, time::timeout};
1010

@@ -520,7 +520,7 @@ fn device_map() {
520520
println!("## Types");
521521
println!();
522522
for ty in app.device_map.types {
523-
let ty = OwnedNamedType::from(*ty);
523+
let ty = OwnedDataModelType::from(*ty);
524524
println!("* {ty}");
525525
}
526526

source/postcard-rpc/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,7 @@ embassy-usb-0_4-server = [
236236
# that feature when `--all-features` is set. This feature is considered unstable
237237
# and should not be relied upon.
238238
_docs-fix = ["dep:ssmarshal"]
239+
240+
[patch.crates-io.postcard-schema]
241+
git = "https://github.com/rslawson/postcard"
242+
features = ["derive"]

source/postcard-rpc/src/host_client/mod.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use maitake_sync::{
2020
wait_map::{WaitError, WakeOutcome},
2121
WaitMap,
2222
};
23-
use postcard_schema::{schema::owned::OwnedNamedType, Schema};
23+
use postcard_schema::{schema::owned::OwnedDataModelType, Schema};
2424
use serde::{de::DeserializeOwned, Deserialize, Serialize};
2525
use tokio::{
2626
select,
@@ -983,7 +983,7 @@ pub struct SchemaReport {
983983
/// All custom types spoken by the device (on any endpoint or topic),
984984
/// as well as all primitive types. In the future, primitive types may
985985
/// be removed.
986-
pub types: HashSet<OwnedNamedType>,
986+
pub types: HashSet<OwnedDataModelType>,
987987
/// All incoming (client to server) topics reported by the device
988988
pub topics_in: Vec<TopicReport>,
989989
/// All outgoing (server to client) topics reported by the device
@@ -1003,45 +1003,47 @@ impl Default for SchemaReport {
10031003

10041004
// We need to pre-populate all of the types we consider primitives:
10051005
// DataModelType::Bool
1006-
me.add_type(OwnedNamedType::from(<bool as Schema>::SCHEMA));
1006+
me.add_type(OwnedDataModelType::from(<bool as Schema>::SCHEMA));
10071007
// DataModelType::I8
1008-
me.add_type(OwnedNamedType::from(<i8 as Schema>::SCHEMA));
1008+
me.add_type(OwnedDataModelType::from(<i8 as Schema>::SCHEMA));
10091009
// DataModelType::U8
1010-
me.add_type(OwnedNamedType::from(<u8 as Schema>::SCHEMA));
1010+
me.add_type(OwnedDataModelType::from(<u8 as Schema>::SCHEMA));
10111011
// DataModelType::I16
1012-
me.add_type(OwnedNamedType::from(<i16 as Schema>::SCHEMA));
1012+
me.add_type(OwnedDataModelType::from(<i16 as Schema>::SCHEMA));
10131013
// DataModelType::I32
1014-
me.add_type(OwnedNamedType::from(<i32 as Schema>::SCHEMA));
1014+
me.add_type(OwnedDataModelType::from(<i32 as Schema>::SCHEMA));
10151015
// DataModelType::I64
1016-
me.add_type(OwnedNamedType::from(<i64 as Schema>::SCHEMA));
1016+
me.add_type(OwnedDataModelType::from(<i64 as Schema>::SCHEMA));
10171017
// DataModelType::I128
1018-
me.add_type(OwnedNamedType::from(<i128 as Schema>::SCHEMA));
1018+
me.add_type(OwnedDataModelType::from(<i128 as Schema>::SCHEMA));
10191019
// DataModelType::U16
1020-
me.add_type(OwnedNamedType::from(<u16 as Schema>::SCHEMA));
1020+
me.add_type(OwnedDataModelType::from(<u16 as Schema>::SCHEMA));
10211021
// DataModelType::U32
1022-
me.add_type(OwnedNamedType::from(<u32 as Schema>::SCHEMA));
1022+
me.add_type(OwnedDataModelType::from(<u32 as Schema>::SCHEMA));
10231023
// DataModelType::U64
1024-
me.add_type(OwnedNamedType::from(<u64 as Schema>::SCHEMA));
1024+
me.add_type(OwnedDataModelType::from(<u64 as Schema>::SCHEMA));
10251025
// DataModelType::U128
1026-
me.add_type(OwnedNamedType::from(<u128 as Schema>::SCHEMA));
1026+
me.add_type(OwnedDataModelType::from(<u128 as Schema>::SCHEMA));
10271027
// // DataModelType::Usize
1028-
// me.add_type(OwnedNamedType::from(<usize as Schema>::SCHEMA));
1028+
// me.add_type(OwnedDataModelType::from(<usize as Schema>::SCHEMA));
10291029
// // DataModelType::Isize
1030-
// me.add_type(OwnedNamedType::from(<isize as Schema>::SCHEMA));
1030+
// me.add_type(OwnedDataModelType::from(<isize as Schema>::SCHEMA));
10311031
// DataModelType::F32
1032-
me.add_type(OwnedNamedType::from(<f32 as Schema>::SCHEMA));
1032+
me.add_type(OwnedDataModelType::from(<f32 as Schema>::SCHEMA));
10331033
// DataModelType::F64
1034-
me.add_type(OwnedNamedType::from(<f64 as Schema>::SCHEMA));
1034+
me.add_type(OwnedDataModelType::from(<f64 as Schema>::SCHEMA));
10351035
// DataModelType::Char
1036-
me.add_type(OwnedNamedType::from(<char as Schema>::SCHEMA));
1036+
me.add_type(OwnedDataModelType::from(<char as Schema>::SCHEMA));
10371037
// DataModelType::String
1038-
me.add_type(OwnedNamedType::from(<String as Schema>::SCHEMA));
1038+
me.add_type(OwnedDataModelType::from(<String as Schema>::SCHEMA));
10391039
// DataModelType::ByteArray
1040-
me.add_type(OwnedNamedType::from(<Vec<u8> as Schema>::SCHEMA));
1040+
me.add_type(OwnedDataModelType::from(<Vec<u8> as Schema>::SCHEMA));
10411041
// DataModelType::Unit
1042-
me.add_type(OwnedNamedType::from(<() as Schema>::SCHEMA));
1042+
me.add_type(OwnedDataModelType::from(<() as Schema>::SCHEMA));
10431043
// DataModelType::Schema
1044-
me.add_type(OwnedNamedType::from(<OwnedNamedType as Schema>::SCHEMA));
1044+
me.add_type(OwnedDataModelType::from(
1045+
<OwnedDataModelType as Schema>::SCHEMA,
1046+
));
10451047

10461048
me
10471049
}
@@ -1055,7 +1057,7 @@ pub struct TopicReport {
10551057
/// The Key of the topic (which hashes the path and type)
10561058
pub key: Key,
10571059
/// The schema of the type of the message
1058-
pub ty: OwnedNamedType,
1060+
pub ty: OwnedDataModelType,
10591061
}
10601062

10611063
/// A description of a single Endpoint
@@ -1066,11 +1068,11 @@ pub struct EndpointReport {
10661068
/// The Key of the request (which hashes the path and type)
10671069
pub req_key: Key,
10681070
/// The schema of the request type
1069-
pub req_ty: OwnedNamedType,
1071+
pub req_ty: OwnedDataModelType,
10701072
/// The Key of the response (which hashes the path and type)
10711073
pub resp_key: Key,
10721074
/// The schema of the response type
1073-
pub resp_ty: OwnedNamedType,
1075+
pub resp_ty: OwnedDataModelType,
10741076
}
10751077

10761078
/// An error that denotes we were unable to resolve the type used by a given key
@@ -1079,7 +1081,7 @@ pub struct UnableToFindType;
10791081

10801082
impl SchemaReport {
10811083
/// Insert a new type
1082-
pub fn add_type(&mut self, t: OwnedNamedType) {
1084+
pub fn add_type(&mut self, t: OwnedDataModelType) {
10831085
self.types.insert(t);
10841086
}
10851087

source/postcard-rpc/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
#![deny(rustdoc::broken_intra_doc_links)]
117117

118118
use header::{VarKey, VarKeyKind};
119-
use postcard_schema::{schema::NamedType, Schema};
119+
use postcard_schema::{schema::DataModelType, Schema};
120120
use serde::{Deserialize, Serialize};
121121

122122
pub mod header;
@@ -432,7 +432,7 @@ pub enum TopicDirection {
432432
/// or out direction.
433433
pub struct DeviceMap {
434434
/// The set of unique types used by all endpoints and topics in this map
435-
pub types: &'static [&'static NamedType],
435+
pub types: &'static [&'static DataModelType],
436436
/// The list of endpoints by path string, request key, and response key
437437
pub endpoints: &'static [(&'static str, Key, Key)],
438438
/// The list of topics (client to server) by path string and topic key
@@ -451,7 +451,7 @@ pub struct DeviceMap {
451451
#[derive(Debug)]
452452
pub struct EndpointMap {
453453
/// The set of unique types used by all endpoints in this map
454-
pub types: &'static [&'static NamedType],
454+
pub types: &'static [&'static DataModelType],
455455
/// The list of endpoints by path string, request key, and response key
456456
pub endpoints: &'static [(&'static str, Key, Key)],
457457
}
@@ -466,7 +466,7 @@ pub struct TopicMap {
466466
/// The direction of these topic messages
467467
pub direction: TopicDirection,
468468
/// The set of unique types used by all topics in this map
469-
pub types: &'static [&'static NamedType],
469+
pub types: &'static [&'static DataModelType],
470470
/// The list of topics by path string and topic key
471471
pub topics: &'static [(&'static str, Key)],
472472
}

source/postcard-rpc/src/macros.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ macro_rules! endpoints {
9696
};
9797
(@ep_tys omit_std=true; $([[$($meta:meta)?] $ep_name:ident])*) => {
9898
const {
99-
const LISTS: &[&[&'static postcard_schema::schema::NamedType]] = &[
99+
const LISTS: &[&[&'static postcard_schema::schema::DataModelType]] = &[
100100
$(
101101
$(#[$meta])?
102102
$crate::unique_types!(<$ep_name as $crate::Endpoint>::Request),
@@ -106,24 +106,24 @@ macro_rules! endpoints {
106106
];
107107

108108
const TTL_COUNT: usize = $crate::uniques::total_len(LISTS);
109-
const BIG_RPT: ([Option<&'static postcard_schema::schema::NamedType>; TTL_COUNT], usize) = $crate::uniques::merge_nty_lists(LISTS);
110-
const SMALL_RPT: [&'static postcard_schema::schema::NamedType; BIG_RPT.1] = $crate::uniques::cruncher(BIG_RPT.0.as_slice());
109+
const BIG_RPT: ([Option<&'static postcard_schema::schema::DataModelType>; TTL_COUNT], usize) = $crate::uniques::merge_dmt_lists(LISTS);
110+
const SMALL_RPT: [&'static postcard_schema::schema::DataModelType; BIG_RPT.1] = $crate::uniques::cruncher(BIG_RPT.0.as_slice());
111111
SMALL_RPT.as_slice()
112112
}
113113
};
114114
(@ep_tys omit_std=false; $([[$($meta:meta)?] $ep_name:ident])*) => {
115115
const {
116-
const USER_TYS: &[&'static postcard_schema::schema::NamedType] =
116+
const USER_TYS: &[&'static postcard_schema::schema::DataModelType] =
117117
$crate::endpoints!(@ep_tys omit_std=true; $([[$($meta)?] $ep_name])*);
118-
const STD_TYS: &[&'static postcard_schema::schema::NamedType]
118+
const STD_TYS: &[&'static postcard_schema::schema::DataModelType]
119119
= $crate::standard_icd::STANDARD_ICD_ENDPOINTS.types;
120120

121-
const BOTH: &[&[&'static postcard_schema::schema::NamedType]] = &[
121+
const BOTH: &[&[&'static postcard_schema::schema::DataModelType]] = &[
122122
USER_TYS, STD_TYS,
123123
];
124124
const TTL_COUNT: usize = $crate::uniques::total_len(BOTH);
125-
const BIG_RPT: ([Option<&'static postcard_schema::schema::NamedType>; TTL_COUNT], usize) = $crate::uniques::merge_nty_lists(BOTH);
126-
const SMALL_RPT: [&'static postcard_schema::schema::NamedType; BIG_RPT.1] = $crate::uniques::cruncher(BIG_RPT.0.as_slice());
125+
const BIG_RPT: ([Option<&'static postcard_schema::schema::DataModelType>; TTL_COUNT], usize) = $crate::uniques::merge_dmt_lists(BOTH);
126+
const SMALL_RPT: [&'static postcard_schema::schema::DataModelType; BIG_RPT.1] = $crate::uniques::cruncher(BIG_RPT.0.as_slice());
127127
SMALL_RPT.as_slice()
128128
}
129129
};
@@ -279,36 +279,36 @@ macro_rules! topics {
279279
};
280280
(@tp_tys ( $dir:expr ) omit_std=true; $([[$($meta:meta)?] $tp_name:ident])*) => {
281281
const {
282-
const LISTS: &[&[&'static postcard_schema::schema::NamedType]] = &[
282+
const LISTS: &[&[&'static postcard_schema::schema::DataModelType]] = &[
283283
$(
284284
$(#[$meta])?
285285
$crate::unique_types!(<$tp_name as $crate::Topic>::Message),
286286
)*
287287
];
288288

289289
const TTL_COUNT: usize = $crate::uniques::total_len(LISTS);
290-
const BIG_RPT: ([Option<&'static postcard_schema::schema::NamedType>; TTL_COUNT], usize) = $crate::uniques::merge_nty_lists(LISTS);
291-
const SMALL_RPT: [&'static postcard_schema::schema::NamedType; BIG_RPT.1] = $crate::uniques::cruncher(BIG_RPT.0.as_slice());
290+
const BIG_RPT: ([Option<&'static postcard_schema::schema::DataModelType>; TTL_COUNT], usize) = $crate::uniques::merge_dmt_lists(LISTS);
291+
const SMALL_RPT: [&'static postcard_schema::schema::DataModelType; BIG_RPT.1] = $crate::uniques::cruncher(BIG_RPT.0.as_slice());
292292
SMALL_RPT.as_slice()
293293
}
294294
};
295295
(@tp_tys ( $dir:expr ) omit_std=false; $([[$($meta:meta)?] $tp_name:ident])*) => {
296296
const {
297-
const USER_TYS: &[&'static postcard_schema::schema::NamedType] =
297+
const USER_TYS: &[&'static postcard_schema::schema::DataModelType] =
298298
$crate::topics!(@tp_tys ( $dir ) omit_std=true; $([[$($meta)?] $tp_name])*);
299-
const STD_TYS: &[&'static postcard_schema::schema::NamedType] = const {
299+
const STD_TYS: &[&'static postcard_schema::schema::DataModelType] = const {
300300
match $dir {
301301
$crate::TopicDirection::ToServer => $crate::standard_icd::STANDARD_ICD_TOPICS_IN.types,
302302
$crate::TopicDirection::ToClient => $crate::standard_icd::STANDARD_ICD_TOPICS_OUT.types,
303303
}
304304
};
305305

306-
const BOTH: &[&[&'static postcard_schema::schema::NamedType]] = &[
306+
const BOTH: &[&[&'static postcard_schema::schema::DataModelType]] = &[
307307
STD_TYS, USER_TYS,
308308
];
309309
const TTL_COUNT: usize = $crate::uniques::total_len(BOTH);
310-
const BIG_RPT: ([Option<&'static postcard_schema::schema::NamedType>; TTL_COUNT], usize) = $crate::uniques::merge_nty_lists(BOTH);
311-
const SMALL_RPT: [&'static postcard_schema::schema::NamedType; BIG_RPT.1] = $crate::uniques::cruncher(BIG_RPT.0.as_slice());
310+
const BIG_RPT: ([Option<&'static postcard_schema::schema::DataModelType>; TTL_COUNT], usize) = $crate::uniques::merge_dmt_lists(BOTH);
311+
const SMALL_RPT: [&'static postcard_schema::schema::DataModelType; BIG_RPT.1] = $crate::uniques::cruncher(BIG_RPT.0.as_slice());
312312
SMALL_RPT.as_slice()
313313
}
314314
};
@@ -431,7 +431,7 @@ macro_rules! sender_fmt {
431431

432432
#[cfg(test)]
433433
mod endpoints_test {
434-
use postcard_schema::{schema::owned::OwnedNamedType, Schema};
434+
use postcard_schema::{schema::owned::OwnedDataModelType, Schema};
435435
use serde::{Deserialize, Serialize};
436436

437437
#[derive(Serialize, Deserialize, Schema)]
@@ -471,7 +471,7 @@ mod endpoints_test {
471471
#[test]
472472
fn eps() {
473473
for ep in ENDPOINT_LIST.types {
474-
println!("{}", OwnedNamedType::from(*ep));
474+
println!("{}", OwnedDataModelType::from(*ep));
475475
}
476476
assert_eq!(ENDPOINT_LIST.types.len(), 3);
477477
for ep in ENDPOINT_LIST.endpoints {
@@ -483,13 +483,13 @@ mod endpoints_test {
483483
#[test]
484484
fn tps() {
485485
for tp in TOPICS_IN_LIST.types {
486-
println!("TY IN: {}", OwnedNamedType::from(*tp));
486+
println!("TY IN: {}", OwnedDataModelType::from(*tp));
487487
}
488488
for tp in TOPICS_IN_LIST.topics {
489489
println!("TP IN: {}", tp.0);
490490
}
491491
for tp in TOPICS_OUT_LIST.types {
492-
println!("TY OUT: {}", OwnedNamedType::from(*tp));
492+
println!("TY OUT: {}", OwnedDataModelType::from(*tp));
493493
}
494494
for tp in TOPICS_OUT_LIST.topics {
495495
println!("TP OUT: {}", tp.0);

source/postcard-rpc/src/server/dispatch_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,15 @@ macro_rules! define_dispatch {
406406
) -> Self {
407407
const MAP: &$crate::DeviceMap = &$crate::DeviceMap {
408408
types: const {
409-
const LISTS: &[&[&'static postcard_schema::schema::NamedType]] = &[
409+
const LISTS: &[&[&'static postcard_schema::schema::DataModelType]] = &[
410410
$endpoint_list.types,
411411
$topic_in_list.types,
412412
$topic_out_list.types,
413413
];
414414
const TTL_COUNT: usize = $endpoint_list.types.len() + $topic_in_list.types.len() + $topic_out_list.types.len();
415415

416-
const BIG_RPT: ([Option<&'static postcard_schema::schema::NamedType>; TTL_COUNT], usize) = $crate::uniques::merge_nty_lists(LISTS);
417-
const SMALL_RPT: [&'static postcard_schema::schema::NamedType; BIG_RPT.1] = $crate::uniques::cruncher(BIG_RPT.0.as_slice());
416+
const BIG_RPT: ([Option<&'static postcard_schema::schema::DataModelType>; TTL_COUNT], usize) = $crate::uniques::merge_dmt_lists(LISTS);
417+
const SMALL_RPT: [&'static postcard_schema::schema::DataModelType; BIG_RPT.1] = $crate::uniques::cruncher(BIG_RPT.0.as_slice());
418418
SMALL_RPT.as_slice()
419419
},
420420
endpoints: &$endpoint_list.endpoints,

source/postcard-rpc/src/server/impls/embassy_usb_v0_4.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,13 @@ impl<M: RawMutex + 'static, D: Driver<'static> + 'static> WireTx for EUsbWireTx<
456456
// Calculate the TOTAL amount
457457
let act_used = ttl_len - remain;
458458

459-
send_all::<D>(ep_in, &tx_buf[..act_used], pending_frame, *timeout_ms_per_frame).await
459+
send_all::<D>(
460+
ep_in,
461+
&tx_buf[..act_used],
462+
pending_frame,
463+
*timeout_ms_per_frame,
464+
)
465+
.await
460466
}
461467
}
462468

source/postcard-rpc/src/standard_icd.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use postcard_schema::Schema;
77
use serde::{Deserialize, Serialize};
88

99
#[cfg(not(feature = "use-std"))]
10-
use postcard_schema::schema::NamedType;
10+
use postcard_schema::schema::DataModelType;
1111

1212
#[cfg(feature = "use-std")]
13-
use postcard_schema::schema::owned::OwnedNamedType;
13+
use postcard_schema::schema::owned::OwnedDataModelType;
1414

1515
/// The calculated Key for the type [`WireError`] and the path [`ERROR_PATH`]
1616
pub const ERROR_KEY: Key = Key::for_path::<WireError>(ERROR_PATH);
@@ -62,7 +62,7 @@ pub enum WireError {
6262
#[derive(Serialize, Schema, Debug, PartialEq, Copy, Clone)]
6363
pub enum SchemaData<'a> {
6464
/// A single Type
65-
Type(&'a NamedType),
65+
Type(&'a DataModelType),
6666
/// A single Endpoint
6767
Endpoint {
6868
/// The path of the endpoint
@@ -88,7 +88,7 @@ pub enum SchemaData<'a> {
8888
#[derive(Serialize, Deserialize, Schema, Debug, PartialEq, Clone)]
8989
pub enum OwnedSchemaData {
9090
/// A single Type
91-
Type(OwnedNamedType),
91+
Type(OwnedDataModelType),
9292
/// A single Endpoint
9393
Endpoint {
9494
/// The path of the endpoint

0 commit comments

Comments
 (0)