Skip to content

Commit efb3779

Browse files
authored
Flatten the module hierarchy (#248)
The modules for clients/services/publishers/subscriptions are moved up from the node/ directory into the main directory. This way, the node module only contains the implementation of the actual Node type. Even though logically, a subscription for instance is a "part of" a node, the module layout should not mirror this hierarchy, or we'd also move the node module below the context module and the directories would become too nested. This also mirrors the layout in rclcpp.
1 parent d3b1171 commit efb3779

File tree

8 files changed

+18
-23
lines changed

8 files changed

+18
-23
lines changed
File renamed without changes.

rclrs/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,29 @@
66
//! [1]: https://github.com/ros2-rust/ros2_rust/blob/main/README.md
77
88
mod arguments;
9+
mod client;
910
mod context;
1011
mod error;
1112
mod node;
1213
mod parameter;
14+
mod publisher;
1315
mod qos;
16+
mod service;
17+
mod subscription;
1418
mod wait;
1519

1620
mod rcl_bindings;
1721

1822
pub use arguments::*;
23+
pub use client::*;
1924
pub use context::*;
2025
pub use error::*;
2126
pub use node::*;
2227
pub use parameter::*;
28+
pub use publisher::*;
2329
pub use qos::*;
30+
pub use service::*;
31+
pub use subscription::*;
2432
pub use wait::*;
2533

2634
use rcl_bindings::rcl_context_is_valid;

rclrs/src/node.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
mod builder;
2-
mod client;
32
mod graph;
4-
mod publisher;
5-
mod service;
6-
mod subscription;
73
pub use self::builder::*;
8-
pub use self::client::*;
94
pub use self::graph::*;
10-
pub use self::publisher::*;
11-
pub use self::service::*;
12-
pub use self::subscription::*;
135

146
use crate::rcl_bindings::*;
15-
use crate::{Context, ParameterOverrideMap, QoSProfile, RclrsError, ToResult};
7+
use crate::{
8+
Client, ClientBase, Context, ParameterOverrideMap, Publisher, QoSProfile, RclrsError, Service,
9+
ServiceBase, Subscription, SubscriptionBase, ToResult,
10+
};
1611

1712
use std::cmp::PartialEq;
1813
use std::ffi::CStr;
@@ -70,7 +65,7 @@ unsafe impl Send for rcl_node_t {}
7065
/// [3]: crate::NodeBuilder::new
7166
/// [4]: crate::NodeBuilder::namespace
7267
pub struct Node {
73-
rcl_node_mtx: Arc<Mutex<rcl_node_t>>,
68+
pub(crate) rcl_node_mtx: Arc<Mutex<rcl_node_t>>,
7469
pub(crate) rcl_context_mtx: Arc<Mutex<rcl_context_t>>,
7570
pub(crate) clients: Vec<Weak<dyn ClientBase>>,
7671
pub(crate) services: Vec<Weak<dyn ServiceBase>>,
@@ -184,14 +179,11 @@ impl Node {
184179
///
185180
/// [1]: crate::Client
186181
// TODO: make client's lifetime depend on node's lifetime
187-
pub fn create_client<T>(
188-
&mut self,
189-
topic: &str,
190-
) -> Result<Arc<crate::node::client::Client<T>>, RclrsError>
182+
pub fn create_client<T>(&mut self, topic: &str) -> Result<Arc<Client<T>>, RclrsError>
191183
where
192184
T: rosidl_runtime_rs::Service,
193185
{
194-
let client = Arc::new(crate::node::client::Client::<T>::new(self, topic)?);
186+
let client = Arc::new(Client::<T>::new(self, topic)?);
195187
self.clients
196188
.push(Arc::downgrade(&client) as Weak<dyn ClientBase>);
197189
Ok(client)
@@ -220,14 +212,12 @@ impl Node {
220212
&mut self,
221213
topic: &str,
222214
callback: F,
223-
) -> Result<Arc<crate::node::service::Service<T>>, RclrsError>
215+
) -> Result<Arc<Service<T>>, RclrsError>
224216
where
225217
T: rosidl_runtime_rs::Service,
226218
F: Fn(&rmw_request_id_t, T::Request) -> T::Response + 'static + Send,
227219
{
228-
let service = Arc::new(crate::node::service::Service::<T>::new(
229-
self, topic, callback,
230-
)?);
220+
let service = Arc::new(Service::<T>::new(self, topic, callback)?);
231221
self.services
232222
.push(Arc::downgrade(&service) as Weak<dyn ServiceBase>);
233223
Ok(service)
File renamed without changes.

rclrs/src/node/service.rs renamed to rclrs/src/service.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ use std::sync::atomic::AtomicBool;
44
use std::sync::{Arc, Mutex, MutexGuard};
55

66
use crate::error::{RclReturnCode, ToResult};
7-
use crate::Node;
8-
use crate::{rcl_bindings::*, RclrsError};
7+
use crate::{rcl_bindings::*, MessageCow, Node, RclrsError};
98

109
use rosidl_runtime_rs::Message;
1110

12-
use crate::node::publisher::MessageCow;
13-
1411
// SAFETY: The functions accessing this type, including drop(), shouldn't care about the thread
1512
// they are running in. Therefore, this type can be safely sent to another thread.
1613
unsafe impl Send for rcl_service_t {}
File renamed without changes.

0 commit comments

Comments
 (0)