Skip to content

Commit 17c7a7e

Browse files
committed
fix: remove explicit impl ZMessage conflicting with blanket impl
After introducing the ZMessage blanket impl, all manual 'impl ZMessage for T {}' in examples, tests, and codegen templates became orphan conflicts. Remove them. Also add .with_serdes::<SerdeCdrSerdes>() at serde-only pub/sub call sites (z_custom_message example, pubsub tests) where NativeCdrSerdes cannot satisfy the ZSerdes<T> bound.
1 parent 24c26ea commit 17c7a7e

File tree

8 files changed

+26
-33
lines changed

8 files changed

+26
-33
lines changed

crates/rmw-zenoh-rs/src/msg.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::type_support::MessageTypeSupport;
22
use ros_z::entity::{TypeHash, TypeInfo};
3-
use ros_z::msg::{ZDeserializer, ZMessage, ZSerdes, ZSerializer, ZService};
3+
use ros_z::msg::{ZDeserializer, ZSerdes, ZSerializer, ZService};
44
use ros_z::ros_msg::WithTypeInfo;
55
use ros_z::{MessageTypeInfo, ServiceTypeInfo};
66

@@ -132,8 +132,6 @@ impl ZSerdes<RosMessage> for RosSerdes {
132132
}
133133
}
134134

135-
impl ZMessage for RosMessage {}
136-
137135
impl MessageTypeInfo for RosMessage {
138136
// Static methods return placeholder values since RosMessage is a generic wrapper
139137
// The actual type info varies per instance

crates/ros-z-codegen/src/protobuf_generator.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ impl ProtobufMessageGenerator {
209209
combined_output.push_str("#[allow(unused_imports)]\n");
210210
combined_output.push_str("use ros_z::ros_msg::WithTypeInfo;\n");
211211
combined_output.push_str("#[allow(unused_imports)]\n");
212-
combined_output.push_str("use ros_z::msg::ZMessage;\n");
213-
combined_output.push_str("#[allow(unused_imports)]\n");
214212
combined_output.push_str("use ros_z::msg::ProtobufSerdes;\n\n");
215213

216214
// Compile all proto files at once to avoid duplicates
@@ -311,8 +309,6 @@ impl ProtobufMessageGenerator {
311309
312310
impl ::ros_z::WithTypeInfo for {proto_type} {{}}
313311
314-
impl ::ros_z::msg::ZMessage for {proto_type} {{}}
315-
316312
"#
317313
));
318314
}

crates/ros-z/examples/dynamic_message/interop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
use ros_z::{
99
dynamic::{DynamicMessage, FieldType, MessageSchema},
10-
msg::{NativeCdrSerdes, ZMessage, ZSerdes},
10+
msg::{NativeCdrSerdes, ZSerdes},
1111
};
1212
use ros_z_msgs::{
1313
geometry_msgs::{Point, Twist, Vector3},

crates/ros-z/examples/protobuf_demo/src/types.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use ros_z::{
33
MessageTypeInfo, ServiceTypeInfo, WithTypeInfo,
44
entity::TypeHash,
5-
msg::{ProtobufSerdes, ZMessage, ZService},
5+
msg::{ProtobufSerdes, ZService},
66
};
77

88
// Include protobuf messages generated from sensor_data.proto
@@ -26,8 +26,6 @@ impl MessageTypeInfo for SensorData {
2626

2727
impl WithTypeInfo for SensorData {}
2828

29-
impl ZMessage for SensorData {}
30-
3129
// SensorData uses serde/CDR for backward compatibility with the original pub/sub demo
3230

3331
// ========== CalculateRequest Trait Implementations ==========
@@ -44,8 +42,6 @@ impl MessageTypeInfo for CalculateRequest {
4442

4543
impl WithTypeInfo for CalculateRequest {}
4644

47-
impl ZMessage for CalculateRequest {}
48-
4945
// ========== CalculateResponse Trait Implementations ==========
5046

5147
impl MessageTypeInfo for CalculateResponse {
@@ -60,8 +56,6 @@ impl MessageTypeInfo for CalculateResponse {
6056

6157
impl WithTypeInfo for CalculateResponse {}
6258

63-
impl ZMessage for CalculateResponse {}
64-
6559
// ========== Calculate Service Definition ==========
6660

6761
pub struct Calculate;

crates/ros-z/examples/z_custom_message.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ use std::time::Duration;
22

33
use clap::Parser;
44
use ros_z::{
5-
Builder, MessageTypeInfo, Result, ServiceTypeInfo, context::ZContextBuilder, entity::TypeHash,
6-
msg::ZService,
5+
Builder, MessageTypeInfo, Result, ServiceTypeInfo,
6+
context::ZContextBuilder,
7+
entity::TypeHash,
8+
msg::{SerdeCdrSerdes, ZService},
79
};
810
use serde::{Deserialize, Serialize};
911

@@ -29,8 +31,6 @@ impl MessageTypeInfo for RobotStatus {
2931

3032
impl ros_z::WithTypeInfo for RobotStatus {}
3133

32-
impl ros_z::msg::ZMessage for RobotStatus {}
33-
3434
// Custom service request
3535
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
3636
pub struct NavigateToRequest {
@@ -51,8 +51,6 @@ impl MessageTypeInfo for NavigateToRequest {
5151

5252
impl ros_z::WithTypeInfo for NavigateToRequest {}
5353

54-
impl ros_z::msg::ZMessage for NavigateToRequest {}
55-
5654
// Custom service response
5755
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5856
pub struct NavigateToResponse {
@@ -73,8 +71,6 @@ impl MessageTypeInfo for NavigateToResponse {
7371

7472
impl ros_z::WithTypeInfo for NavigateToResponse {}
7573

76-
impl ros_z::msg::ZMessage for NavigateToResponse {}
77-
7874
// Service type definition
7975
pub struct NavigateTo;
8076

@@ -140,7 +136,10 @@ async fn run_status_publisher(robot_id: String) -> Result<()> {
140136

141137
let ctx = ZContextBuilder::default().build()?;
142138
let node = ctx.create_node("robot_status_publisher").build()?;
143-
let zpub = node.create_pub::<RobotStatus>("/robot_status").build()?;
139+
let zpub = node
140+
.create_pub::<RobotStatus>("/robot_status")
141+
.with_serdes::<SerdeCdrSerdes>()
142+
.build()?;
144143

145144
let mut position_x = 0.0;
146145
let mut position_y = 0.0;
@@ -191,7 +190,10 @@ async fn run_status_subscriber() -> Result<()> {
191190

192191
let ctx = ZContextBuilder::default().build()?;
193192
let node = ctx.create_node("robot_status_subscriber").build()?;
194-
let zsub = node.create_sub::<RobotStatus>("/robot_status").build()?;
193+
let zsub = node
194+
.create_sub::<RobotStatus>("/robot_status")
195+
.with_serdes::<SerdeCdrSerdes>()
196+
.build()?;
195197

196198
loop {
197199
let status = zsub.async_recv().await?;

crates/ros-z/src/dynamic/tests/interop_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::sync::Arc;
88

99
use crate::dynamic::message::DynamicMessage;
1010
use crate::dynamic::schema::{FieldType, MessageSchema};
11-
use crate::msg::{NativeCdrSerdes, ZMessage, ZSerdes};
11+
use crate::msg::{NativeCdrSerdes, ZSerdes};
1212

1313
use ros_z_msgs::geometry_msgs::{Point, Twist, Vector3};
1414
use ros_z_msgs::std_msgs::String as StdString;

crates/ros-z/tests/pubsub.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::{thread, time::Duration};
22

3-
use ros_z::{Builder, TypeHash, ZBuf, context::ZContextBuilder, ros_msg::MessageTypeInfo};
3+
use ros_z::{
4+
Builder, TypeHash, ZBuf, context::ZContextBuilder, msg::SerdeCdrSerdes,
5+
ros_msg::MessageTypeInfo,
6+
};
47
use ros_z_msgs::std_msgs::ByteMultiArray;
58
use serde::{Deserialize, Serialize};
69
use serde_json::json;
@@ -24,8 +27,6 @@ impl MessageTypeInfo for TestMessage {
2427

2528
impl ros_z::ros_msg::WithTypeInfo for TestMessage {}
2629

27-
impl ros_z::msg::ZMessage for TestMessage {}
28-
2930
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
3031
async fn test_basic_pubsub() {
3132
let ctx = ZContextBuilder::default()
@@ -38,11 +39,13 @@ async fn test_basic_pubsub() {
3839

3940
let publisher = node
4041
.create_pub::<TestMessage>("/test_topic")
42+
.with_serdes::<SerdeCdrSerdes>()
4143
.build()
4244
.unwrap();
4345

4446
let subscriber = node
4547
.create_sub::<TestMessage>("/test_topic")
48+
.with_serdes::<SerdeCdrSerdes>()
4649
.build()
4750
.unwrap();
4851

@@ -72,11 +75,13 @@ async fn test_multiple_messages() {
7275

7376
let publisher = node
7477
.create_pub::<TestMessage>("/multi_topic")
78+
.with_serdes::<SerdeCdrSerdes>()
7579
.build()
7680
.unwrap();
7781

7882
let subscriber = node
7983
.create_sub::<TestMessage>("/multi_topic")
84+
.with_serdes::<SerdeCdrSerdes>()
8085
.build()
8186
.unwrap();
8287

@@ -110,11 +115,13 @@ async fn test_large_payload() {
110115

111116
let publisher = node
112117
.create_pub::<TestMessage>("/large_topic")
118+
.with_serdes::<SerdeCdrSerdes>()
113119
.build()
114120
.unwrap();
115121

116122
let subscriber = node
117123
.create_sub::<TestMessage>("/large_topic")
124+
.with_serdes::<SerdeCdrSerdes>()
118125
.build()
119126
.unwrap();
120127

crates/ros-z/tests/service.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ impl MessageTypeInfo for AddTwoIntsRequest {
2626

2727
impl ros_z::WithTypeInfo for AddTwoIntsRequest {}
2828

29-
impl ros_z::msg::ZMessage for AddTwoIntsRequest {}
30-
3129
// Simple test service response
3230
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
3331
struct AddTwoIntsResponse {
@@ -46,8 +44,6 @@ impl MessageTypeInfo for AddTwoIntsResponse {
4644

4745
impl ros_z::WithTypeInfo for AddTwoIntsResponse {}
4846

49-
impl ros_z::msg::ZMessage for AddTwoIntsResponse {}
50-
5147
// Service type definition
5248
struct AddTwoInts;
5349

0 commit comments

Comments
 (0)