Skip to content

Commit

Permalink
Fix several clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry73204 authored and m-dahl committed Apr 8, 2024
1 parent 1758434 commit bd998ab
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
21 changes: 11 additions & 10 deletions r2r/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn generate_bindings(bindgen_dir: &Path) {
};

let msgs_file = bindgen_dir.join(MSGS_FILENAME);
write_to_file(&msgs_file, &pretty_tokenstream(modules)).unwrap();
write_to_file(&msgs_file, pretty_tokenstream(modules)).unwrap();
}

let mod_files: Vec<_> = msgs
Expand All @@ -113,7 +113,7 @@ fn generate_bindings(bindgen_dir: &Path) {
.map(|(prefix, msgs)| {
let prefix_content = match *prefix {
"msg" => {
let msg_snipplets = msgs.into_iter().map(|msg| {
let msg_snipplets = msgs.iter().map(|msg| {
println!("cargo:rustc-cfg=r2r__{}__{}__{}", module, prefix, msg);
r2r_msg_gen::generate_rust_msg(module, prefix, msg)
});
Expand All @@ -124,7 +124,7 @@ fn generate_bindings(bindgen_dir: &Path) {
}
}
"srv" => {
let msg_snipplets = msgs.into_iter().map(|msg| {
let msg_snipplets = msgs.iter().map(|msg| {
let service_snipplet =
r2r_msg_gen::generate_rust_service(module, prefix, msg);
let msg_snipplets = ["Request", "Response"].iter().map(|s| {
Expand Down Expand Up @@ -152,7 +152,7 @@ fn generate_bindings(bindgen_dir: &Path) {
}
}
"action" => {
let msg_snipplets = msgs.into_iter().map(|msg| {
let msg_snipplets = msgs.iter().map(|msg| {
let action_snipplet =
r2r_msg_gen::generate_rust_action(module, prefix, msg);

Expand Down Expand Up @@ -241,7 +241,7 @@ fn generate_bindings(bindgen_dir: &Path) {
let mod_content = quote! { #(#snipplets)* };
let file_name = format!("{}.rs", module);
let mod_file = bindgen_dir.join(&file_name);
write_to_file(&mod_file, &pretty_tokenstream(mod_content)).unwrap();
write_to_file(&mod_file, pretty_tokenstream(mod_content)).unwrap();

file_name
})
Expand All @@ -251,19 +251,19 @@ fn generate_bindings(bindgen_dir: &Path) {
{
let untyped_helper = r2r_msg_gen::generate_untyped_helper(&msg_list);
let untyped_file = bindgen_dir.join(UNTYPED_FILENAME);
write_to_file(&untyped_file, &pretty_tokenstream(untyped_helper)).unwrap();
write_to_file(&untyped_file, pretty_tokenstream(untyped_helper)).unwrap();
}

{
let untyped_service_helper = r2r_msg_gen::generate_untyped_service_helper(&msg_list);
let untyped_service_file = bindgen_dir.join(UNTYPED_SERVICE_FILENAME);
write_to_file(&untyped_service_file, &pretty_tokenstream(untyped_service_helper)).unwrap();
write_to_file(&untyped_service_file, pretty_tokenstream(untyped_service_helper)).unwrap();
}

{
let untyped_action_helper = r2r_msg_gen::generate_untyped_action_helper(&msg_list);
let untyped_action_file = bindgen_dir.join(UNTYPED_ACTION_FILENAME);
write_to_file(&untyped_action_file, &pretty_tokenstream(untyped_action_helper)).unwrap();
write_to_file(&untyped_action_file, pretty_tokenstream(untyped_action_helper)).unwrap();
}

// Save file list
Expand Down Expand Up @@ -292,16 +292,17 @@ fn copy_files(src_dir: &Path, tgt_dir: &Path) {
.for_each(|file_name| {
let src_file = src_dir.join(file_name);
let tgt_file = tgt_dir.join(file_name);
fs::copy(&src_file, &tgt_file).unwrap();
fs::copy(src_file, tgt_file).unwrap();
});

fs::copy(&src_list_file, &tgt_list_file).unwrap();
fs::copy(&src_list_file, tgt_list_file).unwrap();
}

#[cfg(not(feature = "doc-only"))]
fn touch(path: &Path) {
OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path)
.unwrap_or_else(|_| panic!("Unable to create file '{}'", path.display()));
Expand Down
2 changes: 1 addition & 1 deletion r2r/src/action_servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ where
// todo: add logic that replies to the requests
self.result_requests
.entry(uuid)
.or_insert_with(Vec::new)
.or_default()
.push(request_id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion r2r/src/msg_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub trait WrappedTypesupport:

self.copy_to_native(unsafe { msg.as_mut().expect("not null") });

let msg_buf: &mut rcl_serialized_message_t = &mut *msg_buf
let msg_buf: &mut rcl_serialized_message_t = &mut msg_buf
.as_ref()
.map_err(|err| Error::from_rcl_error(*err))?
.borrow_mut();
Expand Down
10 changes: 5 additions & 5 deletions r2r/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl Node {
))?;

let params = self.params.clone();
let params_struct_clone = params_struct.as_ref().map(|p| p.clone());
let params_struct_clone = params_struct.clone();
let set_params_future = set_params_request_stream.for_each(
move |req: ServiceRequest<rcl_interfaces::srv::SetParameters::Service>| {
let mut result = rcl_interfaces::srv::SetParameters::Response::default();
Expand Down Expand Up @@ -339,7 +339,7 @@ impl Node {
))?;

let params = self.params.clone();
let params_struct_clone = params_struct.as_ref().map(|p| p.clone());
let params_struct_clone = params_struct.clone();
let get_params_future = get_params_request_stream.for_each(
move |req: ServiceRequest<rcl_interfaces::srv::GetParameters::Service>| {
let params = params.lock().unwrap();
Expand All @@ -350,7 +350,7 @@ impl Node {
.map(|n| {
// First try to get the parameter from the param structure
if let Some(ps) = &params_struct_clone {
if let Ok(value) = ps.lock().unwrap().get_parameter(&n) {
if let Ok(value) = ps.lock().unwrap().get_parameter(n) {
return value;
}
}
Expand Down Expand Up @@ -481,14 +481,14 @@ impl Node {
return (depth == ListParameters::Request::DEPTH_RECURSIVE as u64)
|| substr.matches(separator).count() < depth as usize;
}
return false;
false
});
get_all || prefix_matches
}) {
result.names.push(name.clone());
if let Some(last_separator) = name.rfind(separator) {
let prefix = &name[0..last_separator];
if result.prefixes.iter().find(|&p| p == prefix) == None {
if result.prefixes.iter().all(|p| p != prefix) {
result.prefixes.push(prefix.to_string());
}
}
Expand Down
1 change: 1 addition & 0 deletions r2r_actions/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ fn generate_bindings(out_file: &Path) {
fn touch(path: &Path) {
OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path)
.unwrap_or_else(|_| panic!("Unable to create file '{}'", path.display()));
Expand Down
6 changes: 3 additions & 3 deletions r2r_msg_gen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn generate_includes(bindgen_dir: &Path, msg_list: &[RosMsg]) {
} = msg;

// filename is certainly CamelCase -> snake_case. convert
let include_filename = camel_to_snake(&name);
let include_filename = camel_to_snake(name);

[
format!("#include <{module}/{prefix}/{include_filename}.h>"),
Expand All @@ -131,7 +131,7 @@ fn generate_includes(bindgen_dir: &Path, msg_list: &[RosMsg]) {
include_lines.par_sort();

// Write the file content
let mut writer = BufWriter::new(File::create(&msg_includes_file).unwrap());
let mut writer = BufWriter::new(File::create(msg_includes_file).unwrap());
for line in include_lines {
writeln!(writer, "{line}").unwrap();
}
Expand Down Expand Up @@ -163,7 +163,6 @@ fn generate_introspecion_map(bindgen_dir: &Path, msg_list: &[RosMsg]) {
);
(key, ident)
})
.map(|(key, ident)| (key, ident))
.collect(),
"action" => {
let iter1 = ACTION_SUFFICES.iter().map(|s| {
Expand Down Expand Up @@ -551,6 +550,7 @@ fn run_dynlink(msg_list: &[RosMsg]) {
fn touch(path: &Path) {
OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path)
.unwrap_or_else(|_| panic!("Unable to create file '{}'", path.display()));
Expand Down
1 change: 1 addition & 0 deletions r2r_rcl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ fn gen_bindings(out_file: &Path) {
fn touch(path: &Path) {
OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path)
.unwrap_or_else(|_| panic!("Unable to create file '{}'", path.display()));
Expand Down

0 comments on commit bd998ab

Please sign in to comment.