Skip to content

Commit c46e2ab

Browse files
committed
Update documentation for the API changes
Signed-off-by: Michael X. Grey <[email protected]>
1 parent 22b528e commit c46e2ab

File tree

15 files changed

+132
-76
lines changed

15 files changed

+132
-76
lines changed

examples/minimal_pub_sub/src/minimal_two_nodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use anyhow::{Error, Result};
88
struct MinimalSubscriber {
99
num_messages: AtomicU32,
1010
node: rclrs::Node,
11-
subscription: Mutex<Option<Arc<rclrs::Subscription<std_msgs::msg::String>>>>,
11+
subscription: Mutex<Option<rclrs::Subscription<std_msgs::msg::String>>>,
1212
}
1313

1414
impl MinimalSubscriber {

examples/rust_pubsub/src/simple_publisher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{sync::Arc, thread, time::Duration};
33
use std_msgs::msg::String as StringMsg;
44

55
struct SimplePublisher {
6-
publisher: Arc<Publisher<StringMsg>>,
6+
publisher: Publisher<StringMsg>,
77
}
88

99
impl SimplePublisher {

examples/rust_pubsub/src/simple_subscriber.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
use std_msgs::msg::String as StringMsg;
88

99
pub struct SimpleSubscriptionNode {
10-
_subscriber: Arc<Subscription<StringMsg>>,
10+
_subscriber: Subscription<StringMsg>,
1111
data: Arc<Mutex<Option<StringMsg>>>,
1212
}
1313

rclrs/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type RequestId = i64;
6767
/// The only available way to instantiate clients is via [`Node::create_client`][1], this is to
6868
/// ensure that [`Node`][2]s can track all the clients that have been created.
6969
///
70-
/// [1]: crate::Node::create_client
70+
/// [1]: crate::NodeState::create_client
7171
/// [2]: crate::Node
7272
pub struct Client<T>
7373
where

rclrs/src/node.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ use rosidl_runtime_rs::Message;
2121
use crate::{
2222
rcl_bindings::*, Client, ClientBase, ClientOptions, Clock, ContextHandle, GuardCondition,
2323
ParameterBuilder, ParameterInterface, ParameterVariant, Parameters, Publisher, PublisherOptions,
24-
RclrsError, Service, ServiceBase, ServiceOptions, Subscription, SubscriptionBase, SubscriptionCallback,
25-
SubscriptionOptions, TimeSource, ENTITY_LIFECYCLE_MUTEX,
24+
PublisherState, RclrsError, Service, ServiceBase, ServiceOptions, ServiceState, Subscription,
25+
SubscriptionBase, SubscriptionCallback, SubscriptionOptions, SubscriptionState, TimeSource,
26+
ENTITY_LIFECYCLE_MUTEX,
2627
};
2728

2829
// SAFETY: The functions accessing this type, including drop(), shouldn't care about the thread
@@ -39,7 +40,7 @@ unsafe impl Send for rcl_node_t {}
3940
/// to exist and be displayed by e.g. `ros2 topic` as long as any one of its primitives is not dropped.
4041
///
4142
/// # Creating
42-
/// Use [`Executor::create_node`] to create a new node. Pass in [`NodeOptions`] to set all the different
43+
/// Use [`Executor::create_node`][7] to create a new node. Pass in [`NodeOptions`] to set all the different
4344
/// options for node creation, or just pass in a string for the node's name if the default options are okay.
4445
///
4546
/// # Naming
@@ -58,27 +59,30 @@ unsafe impl Send for rcl_node_t {}
5859
/// In that sense, the parameters to the node creation functions are only the _default_ namespace and
5960
/// name.
6061
/// See also the [official tutorial][1] on the command line arguments for ROS nodes, and the
61-
/// [`Node::namespace()`] and [`Node::name()`] functions for examples.
62+
/// [`Node::namespace()`][3] and [`Node::name()`][4] functions for examples.
6263
///
6364
/// ## Rules for valid names
6465
/// The rules for valid node names and node namespaces are explained in
65-
/// [`NodeBuilder::new()`][3] and [`NodeBuilder::namespace()`][4].
66+
/// [`NodeOptions::new()`][5] and [`NodeOptions::namespace()`][6].
6667
///
6768
/// The `Node` object is really just a shared [`NodeState`], so see the [`NodeState`]
6869
/// API to see the various operations you can do with a node, such as creating
6970
/// subscriptions, publishers, services, and clients.
7071
///
7172
/// [1]: https://docs.ros.org/en/rolling/Tutorials/Understanding-ROS2-Nodes.html
7273
/// [2]: https://docs.ros.org/en/rolling/How-To-Guides/Node-arguments.html
73-
/// [3]: crate::NodeBuilder::new
74-
/// [4]: crate::NodeBuilder::namespace
74+
/// [3]: NodeState::namespace
75+
/// [4]: NodeState::name
76+
/// [5]: crate::NodeOptions::new
77+
/// [6]: crate::NodeOptions::namespace
78+
/// [7]: crate::Executor::create_node
7579
pub type Node = Arc<NodeState>;
7680

7781
/// The inner state of a [`Node`].
7882
///
7983
/// This is public so that you can choose to put it inside a [`Weak`] if you
8084
/// want to be able to refer to a [`Node`] in a non-owning way. It is generally
81-
/// recommended to manage the [`NodeState`] inside of an [`Arc`], and [`Node`]
85+
/// recommended to manage the `NodeState` inside of an [`Arc`], and [`Node`]
8286
/// is provided as convenience alias for that.
8387
///
8488
/// The public API of the [`Node`] type is implemented via `NodeState`.
@@ -187,7 +191,7 @@ impl NodeState {
187191
/// Returns the fully qualified name of the node.
188192
///
189193
/// The fully qualified name of the node is the node namespace combined with the node name.
190-
/// It is subject to the remappings shown in [`Node::name()`] and [`Node::namespace()`].
194+
/// It is subject to the remappings shown in [`Node::name()`][1] and [`Node::namespace()`][2].
191195
///
192196
/// # Example
193197
/// ```
@@ -200,6 +204,9 @@ impl NodeState {
200204
/// assert_eq!(node.fully_qualified_name(), "/my/namespace/my_node");
201205
/// # Ok::<(), RclrsError>(())
202206
/// ```
207+
///
208+
/// [1]: NodeState::name
209+
/// [2]: NodeState::namespace
203210
pub fn fully_qualified_name(&self) -> String {
204211
self.call_string_getter(rcl_node_get_fully_qualified_name)
205212
}
@@ -246,7 +253,9 @@ impl NodeState {
246253
/// remain the default service options. Note that clients are generally
247254
/// expected to use [reliable][2], so it's best not to change the reliability
248255
/// setting unless you know what you are doing.
256+
///
249257
/// [1]: crate::Client
258+
/// [2]: crate::QoSReliabilityPolicy::Reliable
250259
// TODO: make client's lifetime depend on node's lifetime
251260
pub fn create_client<'a, T>(
252261
&self,
@@ -263,12 +272,12 @@ impl NodeState {
263272
/// Creates a [`GuardCondition`][1] with no callback.
264273
///
265274
/// A weak pointer to the `GuardCondition` is stored within this node.
266-
/// When this node is added to a wait set (e.g. when calling `spin_once`[2]
275+
/// When this node is added to a wait set (e.g. when [spinning][2]
267276
/// with this node as an argument), the guard condition can be used to
268277
/// interrupt the wait.
269278
///
270279
/// [1]: crate::GuardCondition
271-
/// [2]: crate::spin_once
280+
/// [2]: crate::Executor::spin
272281
pub fn create_guard_condition(&self) -> Arc<GuardCondition> {
273282
let guard_condition = Arc::new(GuardCondition::new_with_context_handle(
274283
Arc::clone(&self.handle.context_handle),
@@ -282,12 +291,12 @@ impl NodeState {
282291
/// Creates a [`GuardCondition`][1] with a callback.
283292
///
284293
/// A weak pointer to the `GuardCondition` is stored within this node.
285-
/// When this node is added to a wait set (e.g. when calling `spin_once`[2]
294+
/// When this node is added to a wait set (e.g. when [spinning][2]
286295
/// with this node as an argument), the guard condition can be used to
287296
/// interrupt the wait.
288297
///
289298
/// [1]: crate::GuardCondition
290-
/// [2]: crate::spin_once
299+
/// [2]: crate::Executor::spin
291300
pub fn create_guard_condition_with_callback<F>(&mut self, callback: F) -> Arc<GuardCondition>
292301
where
293302
F: Fn() + Send + Sync + 'static,
@@ -339,11 +348,11 @@ impl NodeState {
339348
pub fn create_publisher<'a, T>(
340349
&self,
341350
options: impl Into<PublisherOptions<'a>>,
342-
) -> Result<Arc<Publisher<T>>, RclrsError>
351+
) -> Result<Publisher<T>, RclrsError>
343352
where
344353
T: Message,
345354
{
346-
let publisher = Arc::new(Publisher::<T>::new(Arc::clone(&self.handle), options)?);
355+
let publisher = Arc::new(PublisherState::<T>::new(Arc::clone(&self.handle), options)?);
347356
Ok(publisher)
348357
}
349358

@@ -396,12 +405,12 @@ impl NodeState {
396405
&self,
397406
options: impl Into<ServiceOptions<'a>>,
398407
callback: F,
399-
) -> Result<Arc<Service<T>>, RclrsError>
408+
) -> Result<Service<T>, RclrsError>
400409
where
401410
T: rosidl_runtime_rs::Service,
402411
F: Fn(&rmw_request_id_t, T::Request) -> T::Response + 'static + Send,
403412
{
404-
let service = Arc::new(Service::<T>::new(
413+
let service = Arc::new(ServiceState::<T>::new(
405414
Arc::clone(&self.handle),
406415
options,
407416
callback,
@@ -460,11 +469,11 @@ impl NodeState {
460469
&self,
461470
options: impl Into<SubscriptionOptions<'a>>,
462471
callback: impl SubscriptionCallback<T, Args>,
463-
) -> Result<Arc<Subscription<T>>, RclrsError>
472+
) -> Result<Subscription<T>, RclrsError>
464473
where
465474
T: Message,
466475
{
467-
let subscription = Arc::new(Subscription::<T>::new(
476+
let subscription = Arc::new(SubscriptionState::<T>::new(
468477
Arc::clone(&self.handle),
469478
options,
470479
callback,

rclrs/src/node/node_options.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ use crate::{
99
QoSProfile, RclrsError, TimeSource, ToResult, ENTITY_LIFECYCLE_MUTEX, QOS_PROFILE_CLOCK,
1010
};
1111

12-
/// A builder for creating a [`Node`][1].
12+
/// A set of options for creating a [`Node`][1].
1313
///
1414
/// The builder pattern allows selectively setting some fields, and leaving all others at their default values.
15-
/// This struct instance can be created via [`Node::builder()`][2].
1615
///
1716
/// The default values for optional fields are:
1817
/// - `namespace: "/"`
@@ -43,7 +42,6 @@ use crate::{
4342
/// ```
4443
///
4544
/// [1]: crate::Node
46-
/// [2]: crate::Node::builder
4745
pub struct NodeOptions {
4846
name: String,
4947
namespace: String,
@@ -68,7 +66,7 @@ impl NodeOptions {
6866
/// - Must not be empty and not be longer than `RMW_NODE_NAME_MAX_NAME_LENGTH`
6967
/// - Must not start with a number
7068
///
71-
/// Note that node name validation is delayed until [`NodeBuilder::build()`][3].
69+
/// Note that node name validation is delayed until [`Executor::create_node`][3].
7270
///
7371
/// # Example
7472
/// ```
@@ -88,7 +86,7 @@ impl NodeOptions {
8886
///
8987
/// [1]: crate::Node#naming
9088
/// [2]: https://docs.ros2.org/latest/api/rmw/validate__node__name_8h.html#a5690a285aed9735f89ef11950b6e39e3
91-
/// [3]: NodeBuilder::build
89+
/// [3]: crate::Executor::create_node
9290
pub fn new(name: impl ToString) -> NodeOptions {
9391
NodeOptions {
9492
name: name.to_string(),
@@ -119,7 +117,7 @@ impl NodeOptions {
119117
/// - Must not contain two or more `/` characters in a row
120118
/// - Must not have a `/` character at the end, except if `/` is the full namespace
121119
///
122-
/// Note that namespace validation is delayed until [`NodeBuilder::build()`][4].
120+
/// Note that namespace validation is delayed until [`Executor::create_node`][4].
123121
///
124122
/// # Example
125123
/// ```
@@ -150,7 +148,7 @@ impl NodeOptions {
150148
/// [1]: crate::Node#naming
151149
/// [2]: http://design.ros2.org/articles/topic_and_service_names.html
152150
/// [3]: https://docs.ros2.org/latest/api/rmw/validate__namespace_8h.html#a043f17d240cf13df01321b19a469ee49
153-
/// [4]: NodeBuilder::build
151+
/// [4]: crate::Executor::create_node
154152
pub fn namespace(mut self, namespace: impl ToString) -> Self {
155153
self.namespace = namespace.to_string();
156154
self

rclrs/src/node/primitive_options.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub struct PrimitiveOptions<'a> {
3939
pub liveliness: Option<QoSLivelinessPolicy>,
4040
/// Override the default [`QoSProfile::liveliness_lease_duration`] for the primitive.
4141
pub liveliness_lease: Option<QoSDuration>,
42-
/// Override the default [`QoSProfile::avoid_ros_namespace_convention`] for the primitive.
43-
pub avoid_ros_namespace_convention: Option<bool>,
42+
/// Override the default [`QoSProfile::avoid_ros_namespace_conventions`] for the primitive.
43+
pub avoid_ros_namespace_conventions: Option<bool>,
4444
}
4545

4646
/// Trait to implicitly convert a compatible object into [`PrimitiveOptions`].
@@ -205,7 +205,7 @@ impl<'a> PrimitiveOptions<'a> {
205205
lifespan: None,
206206
liveliness: None,
207207
liveliness_lease: None,
208-
avoid_ros_namespace_convention: None,
208+
avoid_ros_namespace_conventions: None,
209209
}
210210
}
211211

@@ -239,7 +239,7 @@ impl<'a> PrimitiveOptions<'a> {
239239
qos.liveliness_lease = liveliness_lease;
240240
}
241241

242-
if let Some(convention) = self.avoid_ros_namespace_convention {
242+
if let Some(convention) = self.avoid_ros_namespace_conventions {
243243
qos.avoid_ros_namespace_conventions = convention;
244244
}
245245
}

rclrs/src/parameter.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ enum DeclaredValue {
8282
}
8383

8484
/// Builder used to declare a parameter. Obtain this by calling
85-
/// [`crate::Node::declare_parameter`].
85+
/// [`Node::declare_parameter`][1].
86+
///
87+
/// [1]: crate::NodeState::declare_parameter
8688
#[must_use]
8789
pub struct ParameterBuilder<'a, T: ParameterVariant> {
8890
name: Arc<str>,

rclrs/src/parameter/service.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ use crate::{
1717
// What is used is the Weak that is stored in the node, and is upgraded when spinning.
1818
pub struct ParameterService {
1919
#[allow(dead_code)]
20-
describe_parameters_service: Arc<Service<DescribeParameters>>,
20+
describe_parameters_service: Service<DescribeParameters>,
2121
#[allow(dead_code)]
22-
get_parameter_types_service: Arc<Service<GetParameterTypes>>,
22+
get_parameter_types_service: Service<GetParameterTypes>,
2323
#[allow(dead_code)]
24-
get_parameters_service: Arc<Service<GetParameters>>,
24+
get_parameters_service: Service<GetParameters>,
2525
#[allow(dead_code)]
26-
list_parameters_service: Arc<Service<ListParameters>>,
26+
list_parameters_service: Service<ListParameters>,
2727
#[allow(dead_code)]
28-
set_parameters_service: Arc<Service<SetParameters>>,
28+
set_parameters_service: Service<SetParameters>,
2929
#[allow(dead_code)]
30-
set_parameters_atomically_service: Arc<Service<SetParametersAtomically>>,
30+
set_parameters_atomically_service: Service<SetParametersAtomically>,
3131
}
3232

3333
fn describe_parameters(

rclrs/src/publisher.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,32 @@ impl Drop for PublisherHandle {
4545

4646
/// Struct for sending messages of type `T`.
4747
///
48+
/// Create a publisher using [`Node::create_publisher`][1].
49+
///
4850
/// Multiple publishers can be created for the same topic, in different nodes or the same node.
51+
/// A clone of a `Publisher` will refer to the same publisher instance as the original.
52+
/// The underlying instance is tied to [`PublisherState`] which implements the [`Publisher`] API.
4953
///
5054
/// The underlying RMW will decide on the concrete delivery mechanism (network stack, shared
5155
/// memory, or intraprocess).
5256
///
53-
/// Sending messages does not require calling [`spin`][1] on the publisher's node.
57+
/// Sending messages does not require the node's executor to [spin][2].
58+
///
59+
/// [1]: crate::NodeState::create_publisher
60+
/// [2]: crate::Executor::spin
61+
pub type Publisher<T> = Arc<PublisherState<T>>;
62+
63+
/// The inner state of a [`Publisher`].
64+
///
65+
/// This is public so that you can choose to create a [`Weak`][1] reference to it
66+
/// if you want to be able to refer to a [`Publisher`] in a non-owning way. It is
67+
/// generally recommended to manage the `PublisherState` inside of an [`Arc`],
68+
/// and [`Publisher`] is provided as a convenience alias for that.
69+
///
70+
/// The public API of the [`Publisher`] type is implemented via `PublisherState`.
5471
///
55-
/// [1]: crate::spin
56-
pub struct Publisher<T>
72+
/// [1]: std::sync::Weak
73+
pub struct PublisherState<T>
5774
where
5875
T: Message,
5976
{
@@ -66,12 +83,12 @@ where
6683

6784
// SAFETY: The functions accessing this type, including drop(), shouldn't care about the thread
6885
// they are running in. Therefore, this type can be safely sent to another thread.
69-
unsafe impl<T> Send for Publisher<T> where T: Message {}
86+
unsafe impl<T> Send for PublisherState<T> where T: Message {}
7087
// SAFETY: The type_support_ptr prevents the default Sync impl.
7188
// rosidl_message_type_support_t is a read-only type without interior mutability.
72-
unsafe impl<T> Sync for Publisher<T> where T: Message {}
89+
unsafe impl<T> Sync for PublisherState<T> where T: Message {}
7390

74-
impl<T> Publisher<T>
91+
impl<T> PublisherState<T>
7592
where
7693
T: Message,
7794
{
@@ -179,7 +196,7 @@ where
179196
}
180197
}
181198

182-
impl<T> Publisher<T>
199+
impl<T> PublisherState<T>
183200
where
184201
T: RmwMessage,
185202
{
@@ -260,7 +277,7 @@ impl<'a, T: IntoPrimitiveOptions<'a>> From<T> for PublisherOptions<'a> {
260277
}
261278
}
262279

263-
/// Convenience trait for [`Publisher::publish`].
280+
/// Convenience trait for [`PublisherState::publish`].
264281
pub trait MessageCow<'a, T: Message> {
265282
/// Wrap the owned or borrowed message in a `Cow`.
266283
fn into_cow(self) -> Cow<'a, T>;

0 commit comments

Comments
 (0)