Skip to content

Commit 4440546

Browse files
authored
Linting fixes after logging lifecycle improvements
1 parent 09f5664 commit 4440546

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

rclrs/src/logging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Adapted from https://github.com/sequenceplanner/r2r/blob/89cec03d07a1496a225751159cbc7bfb529d9dd1/r2r/src/utils.rs
44
// Further adapted from https://github.com/mvukov/rules_ros2/pull/371
55

6-
use std::{ffi::CString, sync::Mutex, time::Duration};
6+
use std::{ffi::CString, time::Duration};
77

88
use crate::{rcl_bindings::*, ENTITY_LIFECYCLE_MUTEX};
99

rclrs/src/logging/logging_configuration.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
use std::sync::{Mutex, Weak, LazyLock, Arc};
1+
use std::sync::{Arc, LazyLock, Mutex, Weak};
22

33
use crate::{
4-
RclrsError, ENTITY_LIFECYCLE_MUTEX, ToResult,
54
rcl_bindings::{
6-
rcl_context_t, rcl_arguments_t, rcutils_get_default_allocator,
7-
rcl_logging_configure, rcl_logging_fini,
5+
rcl_arguments_t, rcl_context_t, rcl_logging_configure, rcl_logging_fini,
6+
rcutils_get_default_allocator,
87
},
8+
RclrsError, ToResult, ENTITY_LIFECYCLE_MUTEX,
99
};
1010

11-
1211
struct LoggingConfiguration {
1312
lifecycle: Mutex<Weak<LoggingLifecycle>>,
1413
}
@@ -30,10 +29,13 @@ impl LoggingLifecycle {
3029
}
3130

3231
/// SAFETY: Ensure rcl_context_t is valid before passing it in.
33-
pub(crate) unsafe fn configure(context: &rcl_context_t) -> Result<Arc<LoggingLifecycle>, RclrsError> {
34-
static CONFIGURATION: LazyLock<LoggingConfiguration> = LazyLock::new(
35-
|| LoggingConfiguration { lifecycle: Mutex::new(Weak::new())}
36-
);
32+
pub(crate) unsafe fn configure(
33+
context: &rcl_context_t,
34+
) -> Result<Arc<LoggingLifecycle>, RclrsError> {
35+
static CONFIGURATION: LazyLock<LoggingConfiguration> =
36+
LazyLock::new(|| LoggingConfiguration {
37+
lifecycle: Mutex::new(Weak::new()),
38+
});
3739

3840
let mut lifecycle = CONFIGURATION.lifecycle.lock().unwrap();
3941
if let Some(arc_lifecycle) = lifecycle.upgrade() {
@@ -48,6 +50,8 @@ impl LoggingLifecycle {
4850
impl Drop for LoggingLifecycle {
4951
fn drop(&mut self) {
5052
let _lock = ENTITY_LIFECYCLE_MUTEX.lock().unwrap();
51-
unsafe { rcl_logging_fini(); }
53+
unsafe {
54+
rcl_logging_fini();
55+
}
5256
}
5357
}

rclrs/src/node/graph.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,10 @@ mod tests {
493493
.unwrap();
494494

495495
assert_eq!(names_and_topics.len(), 1);
496-
assert_eq!(names_and_topics.get("/rosout").unwrap().first().unwrap(), "rcl_interfaces/msg/Log");
496+
assert_eq!(
497+
names_and_topics.get("/rosout").unwrap().first().unwrap(),
498+
"rcl_interfaces/msg/Log"
499+
);
497500

498501
let num_publishers = node.count_publishers("/test").unwrap();
499502

@@ -540,7 +543,10 @@ mod tests {
540543
let names_and_topics = node.get_topic_names_and_types().unwrap();
541544

542545
assert_eq!(names_and_topics.len(), 1);
543-
assert_eq!(names_and_topics.get("/rosout").unwrap().first().unwrap(), "rcl_interfaces/msg/Log");
546+
assert_eq!(
547+
names_and_topics.get("/rosout").unwrap().first().unwrap(),
548+
"rcl_interfaces/msg/Log"
549+
);
544550
}
545551

546552
#[test]

rclrs/src/time_source.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ mod tests {
149149

150150
#[test]
151151
fn time_source_default_clock() {
152-
let node = create_node(&Context::new([]).unwrap(), &format!("time_source_test_node_{}", line!())).unwrap();
152+
let node = create_node(
153+
&Context::new([]).unwrap(),
154+
&format!("time_source_test_node_{}", line!()),
155+
)
156+
.unwrap();
153157
// Default clock should be above 0 (use_sim_time is default false)
154158
assert!(node.get_clock().now().nsec > 0);
155159
}

0 commit comments

Comments
 (0)