Skip to content

Commit 9082816

Browse files
Remove leading underscore from private fields (#354)
* Remove leading underscore from private fields Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai> * Revert renaming to suppress unused warning Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai> --------- Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
1 parent f29144b commit 9082816

File tree

5 files changed

+72
-72
lines changed

5 files changed

+72
-72
lines changed

rclrs/src/clock.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ impl From<ClockType> for rcl_clock_type_t {
2828
/// Struct that implements a Clock and wraps `rcl_clock_t`.
2929
#[derive(Clone, Debug)]
3030
pub struct Clock {
31-
_type: ClockType,
32-
_rcl_clock: Arc<Mutex<rcl_clock_t>>,
31+
kind: ClockType,
32+
rcl_clock: Arc<Mutex<rcl_clock_t>>,
3333
// TODO(luca) Implement jump callbacks
3434
}
3535

3636
/// A clock source that can be used to drive the contained clock. Created when a clock of type
3737
/// `ClockType::RosTime` is constructed
3838
pub struct ClockSource {
39-
_rcl_clock: Arc<Mutex<rcl_clock_t>>,
39+
rcl_clock: Arc<Mutex<rcl_clock_t>>,
4040
}
4141

4242
impl Clock {
@@ -54,52 +54,52 @@ impl Clock {
5454
/// to update it
5555
pub fn with_source() -> (Self, ClockSource) {
5656
let clock = Self::make(ClockType::RosTime);
57-
let clock_source = ClockSource::new(clock._rcl_clock.clone());
57+
let clock_source = ClockSource::new(clock.rcl_clock.clone());
5858
(clock, clock_source)
5959
}
6060

6161
/// Creates a new clock of the given `ClockType`.
62-
pub fn new(type_: ClockType) -> (Self, Option<ClockSource>) {
63-
let clock = Self::make(type_);
62+
pub fn new(kind: ClockType) -> (Self, Option<ClockSource>) {
63+
let clock = Self::make(kind);
6464
let clock_source =
65-
matches!(type_, ClockType::RosTime).then(|| ClockSource::new(clock._rcl_clock.clone()));
65+
matches!(kind, ClockType::RosTime).then(|| ClockSource::new(clock.rcl_clock.clone()));
6666
(clock, clock_source)
6767
}
6868

69-
fn make(type_: ClockType) -> Self {
69+
fn make(kind: ClockType) -> Self {
7070
let mut rcl_clock;
7171
unsafe {
7272
// SAFETY: Getting a default value is always safe.
7373
rcl_clock = Self::init_generic_clock();
7474
let mut allocator = rcutils_get_default_allocator();
7575
// Function will return Err(_) only if there isn't enough memory to allocate a clock
7676
// object.
77-
rcl_clock_init(type_.into(), &mut rcl_clock, &mut allocator)
77+
rcl_clock_init(kind.into(), &mut rcl_clock, &mut allocator)
7878
.ok()
7979
.unwrap();
8080
}
8181
Self {
82-
_type: type_,
83-
_rcl_clock: Arc::new(Mutex::new(rcl_clock)),
82+
kind,
83+
rcl_clock: Arc::new(Mutex::new(rcl_clock)),
8484
}
8585
}
8686

8787
/// Returns the clock's `ClockType`.
8888
pub fn clock_type(&self) -> ClockType {
89-
self._type
89+
self.kind
9090
}
9191

9292
/// Returns the current clock's timestamp.
9393
pub fn now(&self) -> Time {
94-
let mut clock = self._rcl_clock.lock().unwrap();
94+
let mut clock = self.rcl_clock.lock().unwrap();
9595
let mut time_point: i64 = 0;
9696
unsafe {
9797
// SAFETY: No preconditions for this function
9898
rcl_clock_get_now(&mut *clock, &mut time_point);
9999
}
100100
Time {
101101
nsec: time_point,
102-
clock: Arc::downgrade(&self._rcl_clock),
102+
clock: Arc::downgrade(&self.rcl_clock),
103103
}
104104
}
105105

@@ -128,14 +128,14 @@ impl Drop for ClockSource {
128128

129129
impl PartialEq for ClockSource {
130130
fn eq(&self, other: &Self) -> bool {
131-
Arc::ptr_eq(&self._rcl_clock, &other._rcl_clock)
131+
Arc::ptr_eq(&self.rcl_clock, &other.rcl_clock)
132132
}
133133
}
134134

135135
impl ClockSource {
136136
/// Sets the value of the current ROS time.
137137
pub fn set_ros_time_override(&self, nanoseconds: i64) {
138-
let mut clock = self._rcl_clock.lock().unwrap();
138+
let mut clock = self.rcl_clock.lock().unwrap();
139139
// SAFETY: Safe if clock jump callbacks are not edited, which is guaranteed
140140
// by the mutex
141141
unsafe {
@@ -147,16 +147,16 @@ impl ClockSource {
147147
}
148148
}
149149

150-
fn new(clock: Arc<Mutex<rcl_clock_t>>) -> Self {
151-
let source = Self { _rcl_clock: clock };
150+
fn new(rcl_clock: Arc<Mutex<rcl_clock_t>>) -> Self {
151+
let source = Self { rcl_clock };
152152
source.set_ros_time_enable(true);
153153
source
154154
}
155155

156156
/// Sets the clock to use ROS Time, if enabled the clock will report the last value set through
157157
/// `Clock::set_ros_time_override(nanoseconds: i64)`.
158158
fn set_ros_time_enable(&self, enable: bool) {
159-
let mut clock = self._rcl_clock.lock().unwrap();
159+
let mut clock = self.rcl_clock.lock().unwrap();
160160
if enable {
161161
// SAFETY: Safe if clock jump callbacks are not edited, which is guaranteed
162162
// by the mutex

rclrs/src/node.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ pub struct Node {
7171
pub(crate) guard_conditions_mtx: Mutex<Vec<Weak<GuardCondition>>>,
7272
pub(crate) services_mtx: Mutex<Vec<Weak<dyn ServiceBase>>>,
7373
pub(crate) subscriptions_mtx: Mutex<Vec<Weak<dyn SubscriptionBase>>>,
74-
_time_source: TimeSource,
75-
_parameter: ParameterInterface,
74+
time_source: TimeSource,
75+
parameter: ParameterInterface,
7676
}
7777

7878
impl Eq for Node {}
@@ -102,7 +102,7 @@ impl Node {
102102

103103
/// Returns the clock associated with this node.
104104
pub fn get_clock(&self) -> Clock {
105-
self._time_source.get_clock()
105+
self.time_source.get_clock()
106106
}
107107

108108
/// Returns the name of the node.
@@ -398,16 +398,16 @@ impl Node {
398398
&'a self,
399399
name: impl Into<Arc<str>>,
400400
) -> ParameterBuilder<'a, T> {
401-
self._parameter.declare(name.into())
401+
self.parameter.declare(name.into())
402402
}
403403

404404
/// Enables usage of undeclared parameters for this node.
405405
///
406406
/// Returns a [`Parameters`] struct that can be used to get and set all parameters.
407407
pub fn use_undeclared_parameters(&self) -> Parameters {
408-
self._parameter.allow_undeclared();
408+
self.parameter.allow_undeclared();
409409
Parameters {
410-
interface: &self._parameter,
410+
interface: &self.parameter,
411411
}
412412
}
413413

rclrs/src/node/builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl NodeBuilder {
281281
};
282282

283283
let rcl_node_mtx = Arc::new(Mutex::new(rcl_node));
284-
let _parameter = ParameterInterface::new(
284+
let parameter = ParameterInterface::new(
285285
&rcl_node_mtx,
286286
&rcl_node_options.arguments,
287287
&rcl_context.global_arguments,
@@ -293,12 +293,12 @@ impl NodeBuilder {
293293
guard_conditions_mtx: Mutex::new(vec![]),
294294
services_mtx: Mutex::new(vec![]),
295295
subscriptions_mtx: Mutex::new(vec![]),
296-
_time_source: TimeSource::builder(self.clock_type)
296+
time_source: TimeSource::builder(self.clock_type)
297297
.clock_qos(self.clock_qos)
298298
.build(),
299-
_parameter,
299+
parameter,
300300
});
301-
node._time_source.attach_node(&node);
301+
node.time_source.attach_node(&node);
302302
Ok(node)
303303
}
304304

rclrs/src/parameter.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl<T: ParameterVariant> TryFrom<ParameterBuilder<'_, T>> for OptionalParameter
430430
name: builder.name,
431431
value,
432432
ranges,
433-
map: Arc::downgrade(&builder.interface._parameter_map),
433+
map: Arc::downgrade(&builder.interface.parameter_map),
434434
_marker: Default::default(),
435435
})
436436
}
@@ -494,7 +494,7 @@ impl<'a, T: ParameterVariant + 'a> TryFrom<ParameterBuilder<'a, T>> for Mandator
494494
name: builder.name,
495495
value,
496496
ranges,
497-
map: Arc::downgrade(&builder.interface._parameter_map),
497+
map: Arc::downgrade(&builder.interface.parameter_map),
498498
_marker: Default::default(),
499499
})
500500
}
@@ -586,7 +586,7 @@ impl<'a, T: ParameterVariant + 'a> TryFrom<ParameterBuilder<'a, T>> for ReadOnly
586586
Ok(ReadOnlyParameter {
587587
name: builder.name,
588588
value,
589-
map: Arc::downgrade(&builder.interface._parameter_map),
589+
map: Arc::downgrade(&builder.interface.parameter_map),
590590
_marker: Default::default(),
591591
})
592592
}
@@ -703,7 +703,7 @@ impl<'a> Parameters<'a> {
703703
///
704704
/// Returns `Some(T)` if a parameter of the requested type exists, `None` otherwise.
705705
pub fn get<T: ParameterVariant>(&self, name: &str) -> Option<T> {
706-
let storage = &self.interface._parameter_map.lock().unwrap().storage;
706+
let storage = &self.interface.parameter_map.lock().unwrap().storage;
707707
let storage = storage.get(name)?;
708708
match storage {
709709
ParameterStorage::Declared(storage) => match &storage.value {
@@ -728,7 +728,7 @@ impl<'a> Parameters<'a> {
728728
name: impl Into<Arc<str>>,
729729
value: T,
730730
) -> Result<(), ParameterValueError> {
731-
let mut map = self.interface._parameter_map.lock().unwrap();
731+
let mut map = self.interface.parameter_map.lock().unwrap();
732732
let name: Arc<str> = name.into();
733733
match map.storage.entry(name) {
734734
Entry::Occupied(mut entry) => {
@@ -767,8 +767,8 @@ impl<'a> Parameters<'a> {
767767
}
768768

769769
pub(crate) struct ParameterInterface {
770-
_parameter_map: Arc<Mutex<ParameterMap>>,
771-
_override_map: ParameterOverrideMap,
770+
parameter_map: Arc<Mutex<ParameterMap>>,
771+
override_map: ParameterOverrideMap,
772772
allow_undeclared: AtomicBool,
773773
// NOTE(luca-della-vedova) add a ParameterService field to this struct to add support for
774774
// services.
@@ -781,14 +781,14 @@ impl ParameterInterface {
781781
global_arguments: &rcl_arguments_t,
782782
) -> Result<Self, RclrsError> {
783783
let rcl_node = rcl_node_mtx.lock().unwrap();
784-
let _override_map = unsafe {
784+
let override_map = unsafe {
785785
let fqn = call_string_getter_with_handle(&rcl_node, rcl_node_get_fully_qualified_name);
786786
resolve_parameter_overrides(&fqn, node_arguments, global_arguments)?
787787
};
788788

789789
Ok(ParameterInterface {
790-
_parameter_map: Default::default(),
791-
_override_map,
790+
parameter_map: Default::default(),
791+
override_map,
792792
allow_undeclared: Default::default(),
793793
})
794794
}
@@ -820,7 +820,7 @@ impl ParameterInterface {
820820
ranges.validate()?;
821821
let override_value: Option<T> = if ignore_override {
822822
None
823-
} else if let Some(override_value) = self._override_map.get(name).cloned() {
823+
} else if let Some(override_value) = self.override_map.get(name).cloned() {
824824
Some(
825825
override_value
826826
.try_into()
@@ -831,7 +831,7 @@ impl ParameterInterface {
831831
};
832832

833833
let prior_value =
834-
if let Some(prior_value) = self._parameter_map.lock().unwrap().storage.get(name) {
834+
if let Some(prior_value) = self.parameter_map.lock().unwrap().storage.get(name) {
835835
match prior_value {
836836
ParameterStorage::Declared(_) => return Err(DeclarationError::AlreadyDeclared),
837837
ParameterStorage::Undeclared(param) => match param.clone().try_into() {
@@ -869,7 +869,7 @@ impl ParameterInterface {
869869
value: DeclaredValue,
870870
options: ParameterOptionsStorage,
871871
) {
872-
self._parameter_map.lock().unwrap().storage.insert(
872+
self.parameter_map.lock().unwrap().storage.insert(
873873
name,
874874
ParameterStorage::Declared(DeclaredStorage {
875875
options,

rclrs/src/time_source.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use std::sync::{Arc, Mutex, RwLock, Weak};
77
/// If the node's `use_sim_time` parameter is set to `true`, the `TimeSource` will subscribe
88
/// to the `/clock` topic and drive the attached clock
99
pub(crate) struct TimeSource {
10-
_node: Mutex<Weak<Node>>,
11-
_clock: RwLock<Clock>,
12-
_clock_source: Arc<Mutex<Option<ClockSource>>>,
13-
_requested_clock_type: ClockType,
14-
_clock_qos: QoSProfile,
15-
_clock_subscription: Mutex<Option<Arc<Subscription<ClockMsg>>>>,
16-
_last_received_time: Arc<Mutex<Option<i64>>>,
17-
_use_sim_time: Mutex<Option<MandatoryParameter<bool>>>,
10+
node: Mutex<Weak<Node>>,
11+
clock: RwLock<Clock>,
12+
clock_source: Arc<Mutex<Option<ClockSource>>>,
13+
requested_clock_type: ClockType,
14+
clock_qos: QoSProfile,
15+
clock_subscription: Mutex<Option<Arc<Subscription<ClockMsg>>>>,
16+
last_received_time: Arc<Mutex<Option<i64>>>,
17+
use_sim_time: Mutex<Option<MandatoryParameter<bool>>>,
1818
}
1919

2020
/// A builder for creating a [`TimeSource`][1].
@@ -56,14 +56,14 @@ impl TimeSourceBuilder {
5656
ClockType::SteadyTime => Clock::steady(),
5757
};
5858
TimeSource {
59-
_node: Mutex::new(Weak::new()),
60-
_clock: RwLock::new(clock),
61-
_clock_source: Arc::new(Mutex::new(None)),
62-
_requested_clock_type: self.clock_type,
63-
_clock_qos: self.clock_qos,
64-
_clock_subscription: Mutex::new(None),
65-
_last_received_time: Arc::new(Mutex::new(None)),
66-
_use_sim_time: Mutex::new(None),
59+
node: Mutex::new(Weak::new()),
60+
clock: RwLock::new(clock),
61+
clock_source: Arc::new(Mutex::new(None)),
62+
requested_clock_type: self.clock_type,
63+
clock_qos: self.clock_qos,
64+
clock_subscription: Mutex::new(None),
65+
last_received_time: Arc::new(Mutex::new(None)),
66+
use_sim_time: Mutex::new(None),
6767
}
6868
}
6969
}
@@ -76,7 +76,7 @@ impl TimeSource {
7676

7777
/// Returns the clock that this TimeSource is controlling.
7878
pub(crate) fn get_clock(&self) -> Clock {
79-
self._clock.read().unwrap().clone()
79+
self.clock.read().unwrap().clone()
8080
}
8181

8282
/// Attaches the given node to to the `TimeSource`, using its interface to read the
@@ -89,27 +89,27 @@ impl TimeSource {
8989
.default(false)
9090
.mandatory()
9191
.unwrap();
92-
*self._node.lock().unwrap() = Arc::downgrade(node);
92+
*self.node.lock().unwrap() = Arc::downgrade(node);
9393
self.set_ros_time_enable(param.get());
94-
*self._use_sim_time.lock().unwrap() = Some(param);
94+
*self.use_sim_time.lock().unwrap() = Some(param);
9595
}
9696

9797
fn set_ros_time_enable(&self, enable: bool) {
98-
if matches!(self._requested_clock_type, ClockType::RosTime) {
99-
let mut clock = self._clock.write().unwrap();
98+
if matches!(self.requested_clock_type, ClockType::RosTime) {
99+
let mut clock = self.clock.write().unwrap();
100100
if enable && matches!(clock.clock_type(), ClockType::SystemTime) {
101101
let (new_clock, mut clock_source) = Clock::with_source();
102-
if let Some(last_received_time) = *self._last_received_time.lock().unwrap() {
102+
if let Some(last_received_time) = *self.last_received_time.lock().unwrap() {
103103
Self::update_clock(&mut clock_source, last_received_time);
104104
}
105105
*clock = new_clock;
106-
*self._clock_source.lock().unwrap() = Some(clock_source);
107-
*self._clock_subscription.lock().unwrap() = Some(self.create_clock_sub());
106+
*self.clock_source.lock().unwrap() = Some(clock_source);
107+
*self.clock_subscription.lock().unwrap() = Some(self.create_clock_sub());
108108
}
109109
if !enable && matches!(clock.clock_type(), ClockType::RosTime) {
110110
*clock = Clock::system();
111-
*self._clock_source.lock().unwrap() = None;
112-
*self._clock_subscription.lock().unwrap() = None;
111+
*self.clock_source.lock().unwrap() = None;
112+
*self.clock_subscription.lock().unwrap() = None;
113113
}
114114
}
115115
}
@@ -119,15 +119,15 @@ impl TimeSource {
119119
}
120120

121121
fn create_clock_sub(&self) -> Arc<Subscription<ClockMsg>> {
122-
let clock = self._clock_source.clone();
123-
let last_received_time = self._last_received_time.clone();
122+
let clock = self.clock_source.clone();
123+
let last_received_time = self.last_received_time.clone();
124124
// Safe to unwrap since the function will only fail if invalid arguments are provided
125-
self._node
125+
self.node
126126
.lock()
127127
.unwrap()
128128
.upgrade()
129129
.unwrap()
130-
.create_subscription::<ClockMsg, _>("/clock", self._clock_qos, move |msg: ClockMsg| {
130+
.create_subscription::<ClockMsg, _>("/clock", self.clock_qos, move |msg: ClockMsg| {
131131
let nanoseconds: i64 =
132132
(msg.clock.sec as i64 * 1_000_000_000) + msg.clock.nanosec as i64;
133133
*last_received_time.lock().unwrap() = Some(nanoseconds);

0 commit comments

Comments
 (0)