Skip to content

Commit c0cbd07

Browse files
committed
Use the appropriate Waitable sub-trait everywhere
1 parent aef9f60 commit c0cbd07

File tree

5 files changed

+18
-30
lines changed

5 files changed

+18
-30
lines changed

rclrs/src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,15 @@ pub fn spin_once(node: &Node, timeout: Option<Duration>) -> Result<(), RclrsErro
5454
)?;
5555

5656
for live_subscription in live_subscriptions {
57-
// SAFETY: The implementation of this trait function guarantees that the subscription
58-
// is not part of any other wait set. (TODO: issue #207)
59-
unsafe { live_subscription.add_to_wait_set(&mut wait_set)? };
57+
wait_set.add_subscription(live_subscription)?;
6058
}
6159

6260
for live_client in live_clients {
63-
// SAFETY: The implementation of this trait function guarantees that the client
64-
// is not part of any other wait set. (TODO: issue #207)
65-
unsafe { live_client.add_to_wait_set(&mut wait_set)? };
61+
wait_set.add_client(live_client)?;
6662
}
6763

6864
for live_service in live_services {
69-
// SAFETY: The implementation of this trait function guarantees that the client
70-
// is not part of any other wait set. (TODO: issue #207)
71-
unsafe { live_service.add_to_wait_set(&mut wait_set)? };
65+
wait_set.add_service(live_service)?;
7266
}
7367

7468
let ready_entities = wait_set.wait(timeout)?;

rclrs/src/node/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ where
8686
}
8787

8888
/// A marker trait to distinguish `Client` waitables from other [`Waitable`]s.
89-
pub(crate) trait ClientWaitable: Waitable {}
89+
pub trait ClientWaitable: Waitable {}
9090

9191
impl<T> ClientWaitable for Client<T> where T: rosidl_runtime_rs::Service {}
9292

rclrs/src/node/service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ where
5757
std::ptr::null_mut(),
5858
)
5959
.ok()?;
60-
wait_set.clients.push(self);
60+
wait_set.services.push(self);
6161
Ok(())
6262
}
6363

@@ -90,7 +90,7 @@ where
9090
}
9191

9292
/// A marker trait to distinguish `Service` waitables from other [`Waitable`]s.
93-
pub(crate) trait ServiceWaitable: Waitable {}
93+
pub trait ServiceWaitable: Waitable {}
9494

9595
impl<T> ServiceWaitable for Service<T> where T: rosidl_runtime_rs::Service {}
9696

rclrs/src/node/subscription.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ where
8686
}
8787

8888
/// A marker trait to distinguish `Subscription` waitables from other [`Waitable`]s.
89-
pub(crate) trait SubscriptionWaitable: Waitable {}
89+
pub trait SubscriptionWaitable: Waitable {}
9090

9191
impl<T> SubscriptionWaitable for Subscription<T> where T: Message {}
9292

rclrs/src/wait.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use crate::error::{to_rclrs_result, RclReturnCode, RclrsError, ToResult};
1919
use crate::rcl_bindings::*;
20-
use crate::{Client, Context, Service, Subscription};
20+
use crate::{ClientWaitable, Context, ServiceWaitable, SubscriptionWaitable};
2121

2222
use std::sync::Arc;
2323
use std::time::Duration;
@@ -59,19 +59,19 @@ pub struct WaitSet {
5959
// The subscriptions that are currently registered in the wait set.
6060
// This correspondence is an invariant that must be maintained by all functions,
6161
// even in the error case.
62-
pub(crate) subscriptions: Vec<Arc<dyn Waitable>>,
63-
pub(crate) clients: Vec<Arc<dyn Waitable>>,
64-
pub(crate) services: Vec<Arc<dyn Waitable>>,
62+
pub(crate) subscriptions: Vec<Arc<dyn SubscriptionWaitable>>,
63+
pub(crate) clients: Vec<Arc<dyn ClientWaitable>>,
64+
pub(crate) services: Vec<Arc<dyn ServiceWaitable>>,
6565
}
6666

6767
/// A list of entities that are ready, returned by [`WaitSet::wait`].
6868
pub struct ReadyEntities {
6969
/// A list of subscriptions that have potentially received messages.
70-
pub subscriptions: Vec<Arc<dyn Waitable>>,
70+
pub subscriptions: Vec<Arc<dyn SubscriptionWaitable>>,
7171
/// A list of clients that have potentially received responses.
72-
pub clients: Vec<Arc<dyn Waitable>>,
72+
pub clients: Vec<Arc<dyn ClientWaitable>>,
7373
/// A list of services that have potentially received requests.
74-
pub services: Vec<Arc<dyn Waitable>>,
74+
pub services: Vec<Arc<dyn ServiceWaitable>>,
7575
}
7676

7777
impl Drop for rcl_wait_set_t {
@@ -135,10 +135,7 @@ impl WaitSet {
135135
///
136136
/// The same client must not be added to multiple wait sets, because that would make it
137137
/// unsafe to simultaneously wait on those wait sets.
138-
pub fn add_client<T: rosidl_runtime_rs::Service>(
139-
&mut self,
140-
client: Arc<Client<T>>,
141-
) -> Result<(), RclrsError> {
138+
pub fn add_client(&mut self, client: Arc<dyn ClientWaitable>) -> Result<(), RclrsError> {
142139
// SAFETY: The implementation of this trait for clients checks that the client
143140
// has not already been added to a different wait set.
144141
unsafe { client.add_to_wait_set(self) }
@@ -153,10 +150,7 @@ impl WaitSet {
153150
///
154151
/// The same service must not be added to multiple wait sets, because that would make it
155152
/// unsafe to simultaneously wait on those wait sets.
156-
pub fn add_service<T: rosidl_runtime_rs::Service>(
157-
&mut self,
158-
service: Arc<Service<T>>,
159-
) -> Result<(), RclrsError> {
153+
pub fn add_service(&mut self, service: Arc<dyn ServiceWaitable>) -> Result<(), RclrsError> {
160154
// SAFETY: The implementation of this trait for services checks that the service
161155
// has not already been added to a different wait set.
162156
unsafe { service.add_to_wait_set(self) }
@@ -171,9 +165,9 @@ impl WaitSet {
171165
///
172166
/// The same subscription must not be added to multiple wait sets, because that would make it
173167
/// unsafe to simultaneously wait on those wait sets.
174-
pub fn add_subscription<T: rosidl_runtime_rs::Message>(
168+
pub fn add_subscription(
175169
&mut self,
176-
subscription: Arc<Subscription<T>>,
170+
subscription: Arc<dyn SubscriptionWaitable>,
177171
) -> Result<(), RclrsError> {
178172
// SAFETY: The implementation of this trait for subscriptions checks that the subscription
179173
// has not already been added to a different wait set.

0 commit comments

Comments
 (0)