From 23296827093e609177ab2a58b5da427fad19b6b4 Mon Sep 17 00:00:00 2001 From: Yuma Hiramatsu Date: Sun, 22 Aug 2021 02:44:30 +0900 Subject: [PATCH 1/9] Set format_code_in_doc_comments true --- rclrust/src/context.rs | 4 +++- rclrust/src/init_options.rs | 8 ++++---- rclrust/src/qos.rs | 12 ++++++------ rustfmt.toml | 1 + 4 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 rustfmt.toml diff --git a/rclrust/src/context.rs b/rclrust/src/context.rs index bab47d0b..0106f72f 100644 --- a/rclrust/src/context.rs +++ b/rclrust/src/context.rs @@ -178,7 +178,9 @@ impl Context { /// /// let ctx = rclrust::init().unwrap(); /// let options = NodeOptions::new(); - /// let node = ctx.create_node_with_ns_and_options("test_node", "ns", &options).unwrap(); + /// let node = ctx + /// .create_node_with_ns_and_options("test_node", "ns", &options) + /// .unwrap(); /// assert_eq!(&node.fully_qualified_name(), "/ns/test_node"); /// ``` pub fn create_node_with_ns_and_options<'a>( diff --git a/rclrust/src/init_options.rs b/rclrust/src/init_options.rs index a4a74600..4e77c639 100644 --- a/rclrust/src/init_options.rs +++ b/rclrust/src/init_options.rs @@ -42,16 +42,16 @@ impl Drop for RclInitOptions { #[derive(Debug)] pub struct InitOptions { options: RclInitOptions, - // shutdown_on_sigint: bool, - // initialize_logging: bool, + /* shutdown_on_sigint: bool, + * initialize_logging: bool, */ } impl InitOptions { pub fn new() -> Result { Ok(Self { options: RclInitOptions::new()?, - // shutdown_on_sigint: true, - // initialize_logging: true, + /* shutdown_on_sigint: true, + * initialize_logging: true, */ }) } diff --git a/rclrust/src/qos.rs b/rclrust/src/qos.rs index 0403b204..f17629a5 100644 --- a/rclrust/src/qos.rs +++ b/rclrust/src/qos.rs @@ -158,7 +158,7 @@ impl QoSProfile { /// # Examples /// /// ``` - /// use rclrust::qos::{QoSProfile, HistoryPolicy}; + /// use rclrust::qos::{HistoryPolicy, QoSProfile}; /// /// let qos = QoSProfile::system_default().history(HistoryPolicy::KeepAll); /// ``` @@ -242,7 +242,7 @@ impl QoSProfile { /// # Examples /// /// ``` - /// use rclrust::qos::{QoSProfile, DurabilityPolicy}; + /// use rclrust::qos::{DurabilityPolicy, QoSProfile}; /// /// let qos = QoSProfile::system_default().durability(DurabilityPolicy::Volatile); /// ``` @@ -282,8 +282,8 @@ impl QoSProfile { /// # Examples /// /// ``` - /// use std::time::Duration; /// use rclrust::qos::QoSProfile; + /// use std::time::Duration; /// /// let qos = QoSProfile::system_default().deadline(Duration::new(5, 0)); /// ``` @@ -297,8 +297,8 @@ impl QoSProfile { /// # Examples /// /// ``` - /// use std::time::Duration; /// use rclrust::qos::QoSProfile; + /// use std::time::Duration; /// /// let qos = QoSProfile::system_default().lifespan(Duration::new(5, 0)); /// ``` @@ -312,7 +312,7 @@ impl QoSProfile { /// # Examples /// /// ``` - /// use rclrust::qos::{QoSProfile, LivelinessPolicy}; + /// use rclrust::qos::{LivelinessPolicy, QoSProfile}; /// /// let qos = QoSProfile::system_default().liveliness(LivelinessPolicy::Automatic); /// ``` @@ -326,8 +326,8 @@ impl QoSProfile { /// # Examples /// /// ``` - /// use std::time::Duration; /// use rclrust::qos::QoSProfile; + /// use std::time::Duration; /// /// let qos = QoSProfile::system_default().liveliness_lease_duration(Duration::new(5, 0)); /// ``` diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..16bdde91 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +format_code_in_doc_comments = true From f2306d46dbb16adb188a7c9a9e099fa39046dc99 Mon Sep 17 00:00:00 2001 From: Yuma Hiramatsu Date: Sun, 22 Aug 2021 02:46:19 +0900 Subject: [PATCH 2/9] Set group_imports "StdExternalCrate" --- rclrust-msg-gen/src/parser/action.rs | 3 +-- rclrust-msg-gen/src/parser/ident.rs | 3 ++- rclrust-msg-gen/src/parser/literal.rs | 3 ++- rclrust-msg-gen/src/parser/member.rs | 3 ++- rclrust-msg-gen/src/parser/message.rs | 4 ++-- rclrust-msg-gen/src/parser/service.rs | 4 ++-- rclrust-msg-gen/src/parser/types.rs | 3 ++- rclrust/examples/parameters.rs | 1 - rclrust/src/log.rs | 3 ++- rclrust/src/qos.rs | 9 ++++++--- rustfmt.toml | 1 + 11 files changed, 22 insertions(+), 15 deletions(-) diff --git a/rclrust-msg-gen/src/parser/action.rs b/rclrust-msg-gen/src/parser/action.rs index 1f58c16d..b317e40b 100644 --- a/rclrust-msg-gen/src/parser/action.rs +++ b/rclrust-msg-gen/src/parser/action.rs @@ -59,10 +59,9 @@ fn parse_action_string(pkg_name: &str, action_name: &str, action_string: &str) - #[cfg(test)] mod test { - use super::*; - use std::path::PathBuf; + use super::*; use crate::types::primitives::*; use crate::types::sequences::*; use crate::types::MemberType; diff --git a/rclrust-msg-gen/src/parser/ident.rs b/rclrust-msg-gen/src/parser/ident.rs index 2c1db3ae..5e339424 100644 --- a/rclrust-msg-gen/src/parser/ident.rs +++ b/rclrust-msg-gen/src/parser/ident.rs @@ -46,9 +46,10 @@ pub fn constant_name(s: &str) -> IResult<&str, &str> { #[cfg(test)] mod test { - use super::*; use anyhow::Result; + use super::*; + #[test] fn parse_member_name() -> Result<()> { assert_eq!(member_name("abc034_fs3_u3")?.1, "abc034_fs3_u3"); diff --git a/rclrust-msg-gen/src/parser/literal.rs b/rclrust-msg-gen/src/parser/literal.rs index bd4f59a1..5b18750f 100644 --- a/rclrust-msg-gen/src/parser/literal.rs +++ b/rclrust-msg-gen/src/parser/literal.rs @@ -204,9 +204,10 @@ pub fn string_literal_sequence(s: &str) -> IResult<&str, Vec> { #[cfg(test)] mod test { - use super::*; use anyhow::Result; + use super::*; + #[test] fn parse_integer_literal() -> Result<()> { assert_eq!(integer_literal("101_010")?.1, 101010); diff --git a/rclrust-msg-gen/src/parser/member.rs b/rclrust-msg-gen/src/parser/member.rs index 4c13378a..07eff3e9 100644 --- a/rclrust-msg-gen/src/parser/member.rs +++ b/rclrust-msg-gen/src/parser/member.rs @@ -102,9 +102,10 @@ pub fn member_def(line: &str) -> Result { #[cfg(test)] mod test { + use anyhow::Result; + use super::*; use crate::types::primitives::BasicType; - use anyhow::Result; #[test] fn parse_member_def() -> Result<()> { diff --git a/rclrust-msg-gen/src/parser/message.rs b/rclrust-msg-gen/src/parser/message.rs index 2d1d23bb..c4292c50 100644 --- a/rclrust-msg-gen/src/parser/message.rs +++ b/rclrust-msg-gen/src/parser/message.rs @@ -59,12 +59,12 @@ pub fn parse_message_string( #[cfg(test)] mod test { - use super::*; + use std::path::PathBuf; + use super::*; use crate::types::primitives::*; use crate::types::sequences::*; use crate::types::*; - use std::path::PathBuf; #[test] fn test_split_once() { diff --git a/rclrust-msg-gen/src/parser/service.rs b/rclrust-msg-gen/src/parser/service.rs index 21163649..f52fe4d1 100644 --- a/rclrust-msg-gen/src/parser/service.rs +++ b/rclrust-msg-gen/src/parser/service.rs @@ -53,10 +53,10 @@ fn parse_service_string(pkg_name: &str, srv_name: &str, service_string: &str) -> #[cfg(test)] mod test { - use super::*; - use std::path::PathBuf; + use super::*; + fn parse_srv_def(srv_name: &str) -> Result { let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join(format!("test_msgs/srv/{}.srv", srv_name)); diff --git a/rclrust-msg-gen/src/parser/types.rs b/rclrust-msg-gen/src/parser/types.rs index 82f96d25..6f92645c 100644 --- a/rclrust-msg-gen/src/parser/types.rs +++ b/rclrust-msg-gen/src/parser/types.rs @@ -146,9 +146,10 @@ fn primitive_type(s: &str) -> IResult<&str, PrimitiveType> { #[cfg(test)] mod test { - use super::*; use anyhow::Result; + use super::*; + #[test] fn test_parse_member_type_basic_type() -> Result<()> { assert_eq!(parse_member_type("int8")?.1, BasicType::I8.into()); diff --git a/rclrust/examples/parameters.rs b/rclrust/examples/parameters.rs index 1ff9f553..5b38d6a6 100644 --- a/rclrust/examples/parameters.rs +++ b/rclrust/examples/parameters.rs @@ -1,5 +1,4 @@ use anyhow::Result; - use rclrust::rclrust_info; use rclrust::{Parameter, ParameterValue}; diff --git a/rclrust/src/log.rs b/rclrust/src/log.rs index aac632b9..5e2417a3 100644 --- a/rclrust/src/log.rs +++ b/rclrust/src/log.rs @@ -213,9 +213,10 @@ macro_rules! rclrust_fatal { #[cfg(test)] mod test { - use super::*; use std::sync::Mutex; + use super::*; + static TEST_MUTEX: Lazy> = Lazy::new(|| Mutex::new(())); #[test] diff --git a/rclrust/src/qos.rs b/rclrust/src/qos.rs index f17629a5..35b70f8c 100644 --- a/rclrust/src/qos.rs +++ b/rclrust/src/qos.rs @@ -282,9 +282,10 @@ impl QoSProfile { /// # Examples /// /// ``` - /// use rclrust::qos::QoSProfile; /// use std::time::Duration; /// + /// use rclrust::qos::QoSProfile; + /// /// let qos = QoSProfile::system_default().deadline(Duration::new(5, 0)); /// ``` pub fn deadline(&mut self, deadline: Duration) -> &mut Self { @@ -297,9 +298,10 @@ impl QoSProfile { /// # Examples /// /// ``` - /// use rclrust::qos::QoSProfile; /// use std::time::Duration; /// + /// use rclrust::qos::QoSProfile; + /// /// let qos = QoSProfile::system_default().lifespan(Duration::new(5, 0)); /// ``` pub fn lifespan(&mut self, lifespan: Duration) -> &mut Self { @@ -326,9 +328,10 @@ impl QoSProfile { /// # Examples /// /// ``` - /// use rclrust::qos::QoSProfile; /// use std::time::Duration; /// + /// use rclrust::qos::QoSProfile; + /// /// let qos = QoSProfile::system_default().liveliness_lease_duration(Duration::new(5, 0)); /// ``` pub fn liveliness_lease_duration(&mut self, liveliness_lease_duration: Duration) -> &mut Self { diff --git a/rustfmt.toml b/rustfmt.toml index 16bdde91..b809d0ff 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,2 @@ format_code_in_doc_comments = true +group_imports = "StdExternalCrate" From 8165ad3958466b70c577e15b09e41113093ae54c Mon Sep 17 00:00:00 2001 From: Yuma Hiramatsu Date: Sun, 22 Aug 2021 02:48:17 +0900 Subject: [PATCH 3/9] Set imports_granularity "Crate" --- rclrust-msg-gen/src/parser/action.rs | 10 ++---- rclrust-msg-gen/src/parser/constant.rs | 18 +++++----- rclrust-msg-gen/src/parser/ident.rs | 14 ++++---- rclrust-msg-gen/src/parser/literal.rs | 18 +++++----- rclrust-msg-gen/src/parser/member.rs | 18 +++++----- rclrust-msg-gen/src/parser/message.rs | 10 ++---- rclrust-msg-gen/src/parser/package.rs | 12 +++---- rclrust-msg-gen/src/parser/service.rs | 6 ++-- rclrust-msg-gen/src/parser/types.rs | 28 +++++++++------ rclrust-msg-gen/src/types/action.rs | 3 +- rclrust-msg-gen/src/types/constant.rs | 6 ++-- rclrust-msg-gen/src/types/member.rs | 3 +- rclrust-msg-gen/src/types/message.rs | 4 +-- rclrust-msg/src/_core/sequence.rs | 3 +- rclrust-msg/src/_core/string.rs | 6 ++-- rclrust-msg/src/_core/traits.rs | 3 +- rclrust/examples/client.rs | 3 +- rclrust/examples/logger.rs | 5 +-- rclrust/examples/parameters.rs | 3 +- rclrust/examples/publisher.rs | 6 ++-- rclrust/examples/raw_subscription.rs | 6 ++-- rclrust/examples/subscription.rs | 3 +- rclrust/examples/timer.rs | 3 +- rclrust/src/client.rs | 34 ++++++++++-------- rclrust/src/clock.rs | 8 ++--- rclrust/src/context.rs | 23 ++++++------ rclrust/src/executor.rs | 11 +++--- rclrust/src/init_options.rs | 4 +-- rclrust/src/internal/ffi.rs | 6 ++-- rclrust/src/log.rs | 14 +++++--- rclrust/src/node.rs | 48 +++++++++++++++----------- rclrust/src/node_options.rs | 4 +-- rclrust/src/parameter/parameters.rs | 7 ++-- rclrust/src/parameter/rcl_params.rs | 6 ++-- rclrust/src/publisher.rs | 24 +++++++------ rclrust/src/qos.rs | 3 +- rclrust/src/service.rs | 22 +++++++----- rclrust/src/subscription.rs | 22 +++++++----- rclrust/src/time.rs | 3 +- rclrust/src/timer.rs | 22 +++++++----- rclrust/src/utility.rs | 3 +- rclrust/src/wait_set.rs | 12 +++---- rustfmt.toml | 1 + 43 files changed, 239 insertions(+), 229 deletions(-) diff --git a/rclrust-msg-gen/src/parser/action.rs b/rclrust-msg-gen/src/parser/action.rs index b317e40b..c408e630 100644 --- a/rclrust-msg-gen/src/parser/action.rs +++ b/rclrust-msg-gen/src/parser/action.rs @@ -1,11 +1,9 @@ -use std::fs; -use std::path::Path; +use std::{fs, path::Path}; use anyhow::{Context, Result}; use regex::Regex; -use super::error::RclMsgError; -use super::message::parse_message_string; +use super::{error::RclMsgError, message::parse_message_string}; use crate::types::Action; const ACTION_GOAL_SUFFIX: &str = "_Goal"; @@ -62,9 +60,7 @@ mod test { use std::path::PathBuf; use super::*; - use crate::types::primitives::*; - use crate::types::sequences::*; - use crate::types::MemberType; + use crate::types::{primitives::*, sequences::*, MemberType}; fn parse_action_def(srv_name: &str) -> Result { let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) diff --git a/rclrust-msg-gen/src/parser/constant.rs b/rclrust-msg-gen/src/parser/constant.rs index 5960df30..08cffdbc 100644 --- a/rclrust-msg-gen/src/parser/constant.rs +++ b/rclrust-msg-gen/src/parser/constant.rs @@ -1,14 +1,14 @@ use anyhow::{ensure, Result}; -use nom::bytes::complete::is_not; -use nom::character::complete::{char, space0, space1}; -use nom::combinator::{eof, recognize}; -use nom::multi::separated_list1; -use nom::sequence::tuple; +use nom::{ + bytes::complete::is_not, + character::complete::{char, space0, space1}, + combinator::{eof, recognize}, + multi::separated_list1, + sequence::tuple, +}; -use super::error::RclMsgError; -use super::{ident, literal, types}; -use crate::types::primitives::PrimitiveType; -use crate::types::{Constant, ConstantType}; +use super::{error::RclMsgError, ident, literal, types}; +use crate::types::{primitives::PrimitiveType, Constant, ConstantType}; fn validate_value(r#type: ConstantType, value: &str) -> Result> { match r#type { diff --git a/rclrust-msg-gen/src/parser/ident.rs b/rclrust-msg-gen/src/parser/ident.rs index 5e339424..8f1fbb2a 100644 --- a/rclrust-msg-gen/src/parser/ident.rs +++ b/rclrust-msg-gen/src/parser/ident.rs @@ -1,9 +1,11 @@ -use nom::branch::alt; -use nom::character::complete::{alphanumeric0, char, one_of}; -use nom::combinator::{opt, recognize}; -use nom::multi::{many1, separated_list0, separated_list1}; -use nom::sequence::{pair, tuple}; -use nom::IResult; +use nom::{ + branch::alt, + character::complete::{alphanumeric0, char, one_of}, + combinator::{opt, recognize}, + multi::{many1, separated_list0, separated_list1}, + sequence::{pair, tuple}, + IResult, +}; fn upperalpha(s: &str) -> IResult<&str, char> { one_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ")(s) diff --git a/rclrust-msg-gen/src/parser/literal.rs b/rclrust-msg-gen/src/parser/literal.rs index 5b18750f..18645cfd 100644 --- a/rclrust-msg-gen/src/parser/literal.rs +++ b/rclrust-msg-gen/src/parser/literal.rs @@ -1,15 +1,15 @@ use std::convert::TryFrom; -use nom::branch::alt; -use nom::bytes::complete::{is_not, tag, tag_no_case, take_while}; -use nom::character::complete::{ - anychar, char, digit1, hex_digit1, none_of, oct_digit1, one_of, space0, +use nom::{ + branch::alt, + bytes::complete::{is_not, tag, tag_no_case, take_while}, + character::complete::{anychar, char, digit1, hex_digit1, none_of, oct_digit1, one_of, space0}, + combinator::{eof, map, map_res, opt, recognize, rest, value, verify}, + multi::{many0, separated_list1}, + number::complete::recognize_float, + sequence::{delimited, pair, tuple}, + IResult, }; -use nom::combinator::{eof, map, map_res, opt, recognize, rest, value, verify}; -use nom::multi::{many0, separated_list1}; -use nom::number::complete::recognize_float; -use nom::sequence::{delimited, pair, tuple}; -use nom::IResult; use crate::types::primitives::{BasicType, GenericString}; diff --git a/rclrust-msg-gen/src/parser/member.rs b/rclrust-msg-gen/src/parser/member.rs index 07eff3e9..c52380e9 100644 --- a/rclrust-msg-gen/src/parser/member.rs +++ b/rclrust-msg-gen/src/parser/member.rs @@ -1,14 +1,14 @@ use anyhow::{ensure, Result}; -use nom::bytes::complete::is_not; -use nom::character::complete::{space0, space1}; -use nom::combinator::{eof, opt, recognize}; -use nom::multi::separated_list1; -use nom::sequence::{preceded, tuple}; +use nom::{ + bytes::complete::is_not, + character::complete::{space0, space1}, + combinator::{eof, opt, recognize}, + multi::separated_list1, + sequence::{preceded, tuple}, +}; -use super::error::RclMsgError; -use super::{ident, literal, types}; -use crate::types::primitives::NestableType; -use crate::types::{Member, MemberType}; +use super::{error::RclMsgError, ident, literal, types}; +use crate::types::{primitives::NestableType, Member, MemberType}; fn nestable_type_default(nestable_type: NestableType, default: &str) -> Result> { match nestable_type { diff --git a/rclrust-msg-gen/src/parser/message.rs b/rclrust-msg-gen/src/parser/message.rs index c4292c50..c961b973 100644 --- a/rclrust-msg-gen/src/parser/message.rs +++ b/rclrust-msg-gen/src/parser/message.rs @@ -1,10 +1,8 @@ -use std::fs; -use std::path::Path; +use std::{fs, path::Path}; use anyhow::{Context, Result}; -use super::constant::constant_def; -use super::member::member_def; +use super::{constant::constant_def, member::member_def}; use crate::types::Message; fn split_once(s: &'_ str, pat: char) -> (&'_ str, Option<&'_ str>) { @@ -62,9 +60,7 @@ mod test { use std::path::PathBuf; use super::*; - use crate::types::primitives::*; - use crate::types::sequences::*; - use crate::types::*; + use crate::types::{primitives::*, sequences::*, *}; #[test] fn test_split_once() { diff --git a/rclrust-msg-gen/src/parser/package.rs b/rclrust-msg-gen/src/parser/package.rs index e70f890f..3c3f7b9f 100644 --- a/rclrust-msg-gen/src/parser/package.rs +++ b/rclrust-msg-gen/src/parser/package.rs @@ -1,12 +1,12 @@ -use std::fs::{self, File}; -use std::io::{BufRead, BufReader}; -use std::path::Path; +use std::{ + fs::{self, File}, + io::{BufRead, BufReader}, + path::Path, +}; use anyhow::Result; -use super::action::parse_action_file; -use super::message::parse_message_file; -use super::service::parse_service_file; +use super::{action::parse_action_file, message::parse_message_file, service::parse_service_file}; use crate::types::Package; const ROSIDL_INTERFACES: &str = "share/ament_index/resource_index/rosidl_interfaces"; diff --git a/rclrust-msg-gen/src/parser/service.rs b/rclrust-msg-gen/src/parser/service.rs index f52fe4d1..81cf5f23 100644 --- a/rclrust-msg-gen/src/parser/service.rs +++ b/rclrust-msg-gen/src/parser/service.rs @@ -1,11 +1,9 @@ -use std::fs; -use std::path::Path; +use std::{fs, path::Path}; use anyhow::{Context, Result}; use regex::Regex; -use super::error::RclMsgError; -use super::message::parse_message_string; +use super::{error::RclMsgError, message::parse_message_string}; use crate::types::Service; const SERVICE_REQUEST_SUFFIX: &str = "_Request"; diff --git a/rclrust-msg-gen/src/parser/types.rs b/rclrust-msg-gen/src/parser/types.rs index 6f92645c..c761ea04 100644 --- a/rclrust-msg-gen/src/parser/types.rs +++ b/rclrust-msg-gen/src/parser/types.rs @@ -1,16 +1,22 @@ use anyhow::anyhow; -use nom::branch::alt; -use nom::bytes::complete::tag; -use nom::character::complete::{char, space1}; -use nom::combinator::{eof, map, map_res, opt, peek}; -use nom::sequence::{delimited, pair, preceded, tuple}; -use nom::IResult; +use nom::{ + branch::alt, + bytes::complete::tag, + character::complete::{char, space1}, + combinator::{eof, map, map_res, opt, peek}, + sequence::{delimited, pair, preceded, tuple}, + IResult, +}; -use super::ident::{message_name, package_name}; -use super::literal::usize_literal; -use crate::types::primitives::*; -use crate::types::sequences::{Array, BoundedSequence, PrimitiveArray, Sequence}; -use crate::types::{ConstantType, MemberType}; +use super::{ + ident::{message_name, package_name}, + literal::usize_literal, +}; +use crate::types::{ + primitives::*, + sequences::{Array, BoundedSequence, PrimitiveArray, Sequence}, + ConstantType, MemberType, +}; pub fn parse_member_type(s: &str) -> IResult<&str, MemberType> { map_res( diff --git a/rclrust-msg-gen/src/types/action.rs b/rclrust-msg-gen/src/types/action.rs index 418becf2..0b64e86e 100644 --- a/rclrust-msg-gen/src/types/action.rs +++ b/rclrust-msg-gen/src/types/action.rs @@ -1,8 +1,7 @@ use heck::SnakeCase; use quote::{format_ident, quote, ToTokens}; -use super::primitives::*; -use super::{Member, Message, Service}; +use super::{primitives::*, Member, Message, Service}; /// An action definition #[derive(Debug, Clone)] diff --git a/rclrust-msg-gen/src/types/constant.rs b/rclrust-msg-gen/src/types/constant.rs index 03458d21..fe482bbf 100644 --- a/rclrust-msg-gen/src/types/constant.rs +++ b/rclrust-msg-gen/src/types/constant.rs @@ -1,7 +1,9 @@ use quote::{quote, ToTokens}; -use super::primitives::{BasicType, GenericUnboundedString, PrimitiveType}; -use super::sequences::PrimitiveArray; +use super::{ + primitives::{BasicType, GenericUnboundedString, PrimitiveType}, + sequences::PrimitiveArray, +}; macro_rules! define_enum_from { ($into_t:ty, $from_t:ty, $path:path) => { diff --git a/rclrust-msg-gen/src/types/member.rs b/rclrust-msg-gen/src/types/member.rs index bd454aa3..943d5cbf 100644 --- a/rclrust-msg-gen/src/types/member.rs +++ b/rclrust-msg-gen/src/types/member.rs @@ -1,7 +1,6 @@ use quote::{quote, ToTokens}; -use super::primitives::*; -use super::sequences::*; +use super::{primitives::*, sequences::*}; macro_rules! define_enum_from { ($into_t:ty, $from_t:ty, $path:path) => { diff --git a/rclrust-msg-gen/src/types/message.rs b/rclrust-msg-gen/src/types/message.rs index 01deec80..1f83147e 100644 --- a/rclrust-msg-gen/src/types/message.rs +++ b/rclrust-msg-gen/src/types/message.rs @@ -1,9 +1,7 @@ use heck::SnakeCase; use quote::{format_ident, quote, ToTokens}; -use super::primitives::*; -use super::sequences::Array; -use super::{ConstantType, MemberType}; +use super::{primitives::*, sequences::Array, ConstantType, MemberType}; /// A member of a structure #[derive(Debug, Clone)] diff --git a/rclrust-msg/src/_core/sequence.rs b/rclrust-msg/src/_core/sequence.rs index 62a3d222..63d2e9f2 100644 --- a/rclrust-msg/src/_core/sequence.rs +++ b/rclrust-msg/src/_core/sequence.rs @@ -1,5 +1,4 @@ -use std::mem::ManuallyDrop; -use std::ops::Deref; +use std::{mem::ManuallyDrop, ops::Deref}; use super::traits::{FFIFromRust, FFIToRust}; diff --git a/rclrust-msg/src/_core/string.rs b/rclrust-msg/src/_core/string.rs index 34f27294..e6274a0c 100644 --- a/rclrust-msg/src/_core/string.rs +++ b/rclrust-msg/src/_core/string.rs @@ -1,5 +1,7 @@ -use std::ffi::{CStr, CString}; -use std::os::raw::c_char; +use std::{ + ffi::{CStr, CString}, + os::raw::c_char, +}; use widestring::{U16CStr, U16CString, U16String}; diff --git a/rclrust-msg/src/_core/traits.rs b/rclrust-msg/src/_core/traits.rs index 6aa3994a..bdb2c7f9 100644 --- a/rclrust-msg/src/_core/traits.rs +++ b/rclrust-msg/src/_core/traits.rs @@ -1,5 +1,4 @@ -use std::convert::TryInto; -use std::os::raw::c_void; +use std::{convert::TryInto, os::raw::c_void}; use array_init::array_init; use widestring::U16String; diff --git a/rclrust/examples/client.rs b/rclrust/examples/client.rs index 358ef16f..819bfc48 100644 --- a/rclrust/examples/client.rs +++ b/rclrust/examples/client.rs @@ -1,6 +1,5 @@ use anyhow::Result; -use rclrust::qos::QoSProfile; -use rclrust::rclrust_info; +use rclrust::{qos::QoSProfile, rclrust_info}; use rclrust_msg::example_interfaces::srv::{AddTwoInts, AddTwoInts_Request}; fn main() -> Result<()> { diff --git a/rclrust/examples/logger.rs b/rclrust/examples/logger.rs index 99013dc9..451156ce 100644 --- a/rclrust/examples/logger.rs +++ b/rclrust/examples/logger.rs @@ -1,6 +1,7 @@ use anyhow::Result; -use rclrust::{rclrust_debug, rclrust_error, rclrust_fatal, rclrust_info, rclrust_warn}; -use rclrust::{Clock, Logger}; +use rclrust::{ + rclrust_debug, rclrust_error, rclrust_fatal, rclrust_info, rclrust_warn, Clock, Logger, +}; use rclrust_msg::geometry_msgs::msg::Twist; fn main() -> Result<()> { diff --git a/rclrust/examples/parameters.rs b/rclrust/examples/parameters.rs index 5b38d6a6..d1fc4fa4 100644 --- a/rclrust/examples/parameters.rs +++ b/rclrust/examples/parameters.rs @@ -1,6 +1,5 @@ use anyhow::Result; -use rclrust::rclrust_info; -use rclrust::{Parameter, ParameterValue}; +use rclrust::{rclrust_info, Parameter, ParameterValue}; fn main() -> Result<()> { let ctx = rclrust::init()?; diff --git a/rclrust/examples/publisher.rs b/rclrust/examples/publisher.rs index 0273b81a..089972fb 100644 --- a/rclrust/examples/publisher.rs +++ b/rclrust/examples/publisher.rs @@ -1,9 +1,7 @@ -use std::thread::sleep; -use std::time::Duration; +use std::{thread::sleep, time::Duration}; use anyhow::Result; -use rclrust::qos::QoSProfile; -use rclrust::rclrust_info; +use rclrust::{qos::QoSProfile, rclrust_info}; use rclrust_msg::std_msgs::msg::String as String_; fn main() -> Result<()> { diff --git a/rclrust/examples/raw_subscription.rs b/rclrust/examples/raw_subscription.rs index 3d420ac0..0546d3e2 100644 --- a/rclrust/examples/raw_subscription.rs +++ b/rclrust/examples/raw_subscription.rs @@ -1,8 +1,6 @@ use anyhow::Result; -use rclrust::qos::QoSProfile; -use rclrust::rclrust_info; -use rclrust_msg::_core::FFIToRust; -use rclrust_msg::std_msgs::msg::String as String_; +use rclrust::{qos::QoSProfile, rclrust_info}; +use rclrust_msg::{_core::FFIToRust, std_msgs::msg::String as String_}; fn main() -> Result<()> { let ctx = rclrust::init()?; diff --git a/rclrust/examples/subscription.rs b/rclrust/examples/subscription.rs index 698d2225..e831d175 100644 --- a/rclrust/examples/subscription.rs +++ b/rclrust/examples/subscription.rs @@ -1,6 +1,5 @@ use anyhow::Result; -use rclrust::qos::QoSProfile; -use rclrust::rclrust_info; +use rclrust::{qos::QoSProfile, rclrust_info}; use rclrust_msg::std_msgs::msg::String as String_; fn main() -> Result<()> { diff --git a/rclrust/examples/timer.rs b/rclrust/examples/timer.rs index c843c9dd..4d909481 100644 --- a/rclrust/examples/timer.rs +++ b/rclrust/examples/timer.rs @@ -1,5 +1,4 @@ -use std::cell::Cell; -use std::time::Duration; +use std::{cell::Cell, time::Duration}; use anyhow::Result; use rclrust::rclrust_info; diff --git a/rclrust/src/client.rs b/rclrust/src/client.rs index 058d3d2d..fdcad5e2 100644 --- a/rclrust/src/client.rs +++ b/rclrust/src/client.rs @@ -1,23 +1,27 @@ -use std::collections::HashMap; -use std::ffi::CString; -use std::marker::PhantomData; -use std::mem::MaybeUninit; -use std::os::raw::c_void; -use std::sync::{Arc, Mutex, Weak}; -use std::time::Duration; +use std::{ + collections::HashMap, + ffi::CString, + marker::PhantomData, + mem::MaybeUninit, + os::raw::c_void, + sync::{Arc, Mutex, Weak}, + time::Duration, +}; use anyhow::{anyhow, Context as _, Result}; use futures::channel::oneshot; use rclrust_msg::_core::{FFIToRust, MessageT, ServiceT}; -use crate::context::Context; -use crate::error::{RclRustError, ToRclRustResult}; -use crate::internal::ffi::*; -use crate::log::Logger; -use crate::node::{Node, RclNode}; -use crate::qos::QoSProfile; -use crate::rclrust_error; -use crate::wait_set::RclWaitSet; +use crate::{ + context::Context, + error::{RclRustError, ToRclRustResult}, + internal::ffi::*, + log::Logger, + node::{Node, RclNode}, + qos::QoSProfile, + rclrust_error, + wait_set::RclWaitSet, +}; #[derive(Debug)] pub(crate) struct RclClient(Box); diff --git a/rclrust/src/clock.rs b/rclrust/src/clock.rs index 7a984242..d8ec6944 100644 --- a/rclrust/src/clock.rs +++ b/rclrust/src/clock.rs @@ -2,11 +2,9 @@ use std::mem::MaybeUninit; use anyhow::{ensure, Context, Result}; -use crate::error::ToRclRustResult; -use crate::impl_from_trait_for_enum; -use crate::log::Logger; -use crate::rclrust_error; -use crate::time::Time; +use crate::{ + error::ToRclRustResult, impl_from_trait_for_enum, log::Logger, rclrust_error, time::Time, +}; /// Time source type, used to indicate the source of a time measurement. #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/rclrust/src/context.rs b/rclrust/src/context.rs index 0106f72f..e4ab52f4 100644 --- a/rclrust/src/context.rs +++ b/rclrust/src/context.rs @@ -1,16 +1,19 @@ -use std::ffi::CString; -use std::os::raw::c_int; -use std::sync::{Arc, Mutex}; +use std::{ + ffi::CString, + os::raw::c_int, + sync::{Arc, Mutex}, +}; use anyhow::{Context as _, Result}; -use crate::error::ToRclRustResult; -use crate::init_options::InitOptions; -use crate::log::Logger; -use crate::log::{logging_output_handler, LOGGER_MUTEX}; -use crate::node::Node; -use crate::node_options::NodeOptions; -use crate::rclrust_error; +use crate::{ + error::ToRclRustResult, + init_options::InitOptions, + log::{logging_output_handler, Logger, LOGGER_MUTEX}, + node::Node, + node_options::NodeOptions, + rclrust_error, +}; #[derive(Debug)] pub(crate) struct RclContext(Box); diff --git a/rclrust/src/executor.rs b/rclrust/src/executor.rs index 9f72fa43..be9a879d 100644 --- a/rclrust/src/executor.rs +++ b/rclrust/src/executor.rs @@ -1,12 +1,11 @@ -use std::sync::{Arc, Weak}; -use std::time::Duration; +use std::{ + sync::{Arc, Weak}, + time::Duration, +}; use anyhow::Result; -use crate::context::Context; -use crate::error::RclRustError; -use crate::node::Node; -use crate::wait_set::RclWaitSet; +use crate::{context::Context, error::RclRustError, node::Node, wait_set::RclWaitSet}; pub fn spin(node: &Arc>) -> Result<()> { let mut exec = SingleThreadExecutor::new(node.context)?; diff --git a/rclrust/src/init_options.rs b/rclrust/src/init_options.rs index 4e77c639..ffc682ac 100644 --- a/rclrust/src/init_options.rs +++ b/rclrust/src/init_options.rs @@ -1,8 +1,6 @@ use anyhow::{Context, Result}; -use crate::error::ToRclRustResult; -use crate::log::Logger; -use crate::rclrust_error; +use crate::{error::ToRclRustResult, log::Logger, rclrust_error}; #[derive(Debug)] pub(crate) struct RclInitOptions(rcl_sys::rcl_init_options_t); diff --git a/rclrust/src/internal/ffi.rs b/rclrust/src/internal/ffi.rs index d2acedbc..7b683dcb 100644 --- a/rclrust/src/internal/ffi.rs +++ b/rclrust/src/internal/ffi.rs @@ -1,5 +1,7 @@ -use std::ffi::{CStr, CString}; -use std::os::raw::c_char; +use std::{ + ffi::{CStr, CString}, + os::raw::c_char, +}; pub unsafe trait SizedFromCChar: Sized { unsafe fn from_c_char(ptr: *const c_char) -> Option; diff --git a/rclrust/src/log.rs b/rclrust/src/log.rs index 5e2417a3..b1b7c693 100644 --- a/rclrust/src/log.rs +++ b/rclrust/src/log.rs @@ -1,13 +1,17 @@ -use std::convert::{TryFrom, TryInto}; -use std::ffi::CString; -use std::os::raw::{c_char, c_int}; +use std::{ + convert::{TryFrom, TryInto}, + ffi::CString, + os::raw::{c_char, c_int}, +}; use anyhow::{Context, Result}; use once_cell::sync::Lazy; use parking_lot::ReentrantMutex; -use crate::error::{RclRustError, ToRclRustResult}; -use crate::impl_from_trait_for_enum; +use crate::{ + error::{RclRustError, ToRclRustResult}, + impl_from_trait_for_enum, +}; #[derive(Debug, Clone, Copy, PartialEq)] pub enum LogSeverity { diff --git a/rclrust/src/node.rs b/rclrust/src/node.rs index bad1272d..e39c9512 100644 --- a/rclrust/src/node.rs +++ b/rclrust/src/node.rs @@ -1,26 +1,32 @@ -use std::ffi::CString; -use std::sync::{Arc, Mutex, Weak}; -use std::time::Duration; +use std::{ + ffi::CString, + sync::{Arc, Mutex, Weak}, + time::Duration, +}; use anyhow::{ensure, Context as _, Result}; -use rclrust_msg::_core::{FFIToRust, MessageT, ServiceT}; -use rclrust_msg::rcl_interfaces::msg::ParameterDescriptor; - -use crate::client::{Client, ClientBase}; -use crate::clock::ClockType; -use crate::context::{Context, RclContext}; -use crate::error::ToRclRustResult; -use crate::internal::ffi::*; -use crate::log::Logger; -use crate::node_options::NodeOptions; -use crate::parameter::{Parameter, ParameterValue, Parameters}; -use crate::publisher::Publisher; -use crate::qos::QoSProfile; -use crate::rclrust_error; -use crate::service::{Service, ServiceBase}; -use crate::subscription::{Subscription, SubscriptionBase}; -use crate::timer::Timer; -use crate::wait_set::RclWaitSet; +use rclrust_msg::{ + _core::{FFIToRust, MessageT, ServiceT}, + rcl_interfaces::msg::ParameterDescriptor, +}; + +use crate::{ + client::{Client, ClientBase}, + clock::ClockType, + context::{Context, RclContext}, + error::ToRclRustResult, + internal::ffi::*, + log::Logger, + node_options::NodeOptions, + parameter::{Parameter, ParameterValue, Parameters}, + publisher::Publisher, + qos::QoSProfile, + rclrust_error, + service::{Service, ServiceBase}, + subscription::{Subscription, SubscriptionBase}, + timer::Timer, + wait_set::RclWaitSet, +}; #[derive(Debug)] pub(crate) struct RclNode(Box); diff --git a/rclrust/src/node_options.rs b/rclrust/src/node_options.rs index d4fc8000..039bbc9f 100644 --- a/rclrust/src/node_options.rs +++ b/rclrust/src/node_options.rs @@ -1,6 +1,4 @@ -use crate::error::ToRclRustResult; -use crate::log::Logger; -use crate::rclrust_error; +use crate::{error::ToRclRustResult, log::Logger, rclrust_error}; #[derive(Debug)] pub(crate) struct RclNodeOptions(rcl_sys::rcl_node_options_t); diff --git a/rclrust/src/parameter/parameters.rs b/rclrust/src/parameter/parameters.rs index e7cef1c6..c126d20d 100644 --- a/rclrust/src/parameter/parameters.rs +++ b/rclrust/src/parameter/parameters.rs @@ -1,14 +1,11 @@ -use std::collections::HashMap; -use std::sync::Mutex; +use std::{collections::HashMap, sync::Mutex}; use anyhow::Result; use super::{ Parameter, ParameterDescriptor, ParameterType, ParameterValue, RclParams, SetParametersResult, }; -use crate::context::RclContext; -use crate::error::RclRustError; -use crate::node::RclNode; +use crate::{context::RclContext, error::RclRustError, node::RclNode}; #[derive(Debug, Default, Clone)] pub struct ParameterInfo { diff --git a/rclrust/src/parameter/rcl_params.rs b/rclrust/src/parameter/rcl_params.rs index 2c7f0fd6..841cb32b 100644 --- a/rclrust/src/parameter/rcl_params.rs +++ b/rclrust/src/parameter/rcl_params.rs @@ -3,8 +3,10 @@ use std::collections::HashMap; use anyhow::{Context, Result}; use super::ParameterValue; -use crate::error::{RclRustError, ToRclRustResult}; -use crate::internal::ffi::{FromCChar, SizedFromCChar}; +use crate::{ + error::{RclRustError, ToRclRustResult}, + internal::ffi::{FromCChar, SizedFromCChar}, +}; #[derive(Debug)] pub struct RclParams(Box<*mut rcl_sys::rcl_params_t>); diff --git a/rclrust/src/publisher.rs b/rclrust/src/publisher.rs index 22952fc2..ec809920 100644 --- a/rclrust/src/publisher.rs +++ b/rclrust/src/publisher.rs @@ -1,17 +1,21 @@ -use std::ffi::CString; -use std::marker::PhantomData; -use std::os::raw::c_void; -use std::sync::{Arc, Mutex}; +use std::{ + ffi::CString, + marker::PhantomData, + os::raw::c_void, + sync::{Arc, Mutex}, +}; use anyhow::{Context, Result}; use rclrust_msg::_core::MessageT; -use crate::error::ToRclRustResult; -use crate::internal::ffi::*; -use crate::log::Logger; -use crate::node::{Node, RclNode}; -use crate::qos::QoSProfile; -use crate::rclrust_error; +use crate::{ + error::ToRclRustResult, + internal::ffi::*, + log::Logger, + node::{Node, RclNode}, + qos::QoSProfile, + rclrust_error, +}; #[derive(Debug)] pub(crate) struct RclPublisher(Box); diff --git a/rclrust/src/qos.rs b/rclrust/src/qos.rs index 35b70f8c..e79c62cf 100644 --- a/rclrust/src/qos.rs +++ b/rclrust/src/qos.rs @@ -1,7 +1,6 @@ use std::time::Duration; -use crate::impl_from_trait_for_enum; -use crate::time::RclDurationT; +use crate::{impl_from_trait_for_enum, time::RclDurationT}; /// QoS reliability enumerations #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/rclrust/src/service.rs b/rclrust/src/service.rs index 3e08be94..fbf93d01 100644 --- a/rclrust/src/service.rs +++ b/rclrust/src/service.rs @@ -1,16 +1,20 @@ -use std::ffi::{c_void, CString}; -use std::mem::MaybeUninit; -use std::sync::{Arc, Mutex}; +use std::{ + ffi::{c_void, CString}, + mem::MaybeUninit, + sync::{Arc, Mutex}, +}; use anyhow::{Context, Result}; use rclrust_msg::_core::{MessageT, ServiceT}; -use crate::error::{RclRustError, ToRclRustResult}; -use crate::internal::ffi::*; -use crate::log::Logger; -use crate::node::{Node, RclNode}; -use crate::qos::QoSProfile; -use crate::rclrust_error; +use crate::{ + error::{RclRustError, ToRclRustResult}, + internal::ffi::*, + log::Logger, + node::{Node, RclNode}, + qos::QoSProfile, + rclrust_error, +}; pub struct RclService(Box); diff --git a/rclrust/src/subscription.rs b/rclrust/src/subscription.rs index c72b6ed5..b4b59dda 100644 --- a/rclrust/src/subscription.rs +++ b/rclrust/src/subscription.rs @@ -1,16 +1,20 @@ -use std::ffi::CString; -use std::os::raw::c_void; -use std::sync::{Arc, Mutex}; +use std::{ + ffi::CString, + os::raw::c_void, + sync::{Arc, Mutex}, +}; use anyhow::{Context, Result}; use rclrust_msg::_core::MessageT; -use crate::error::{RclRustError, ToRclRustResult}; -use crate::internal::ffi::*; -use crate::log::Logger; -use crate::node::{Node, RclNode}; -use crate::qos::QoSProfile; -use crate::rclrust_error; +use crate::{ + error::{RclRustError, ToRclRustResult}, + internal::ffi::*, + log::Logger, + node::{Node, RclNode}, + qos::QoSProfile, + rclrust_error, +}; #[derive(Debug)] pub(crate) struct RclSubscription(Box); diff --git a/rclrust/src/time.rs b/rclrust/src/time.rs index bb161bb6..1898315c 100644 --- a/rclrust/src/time.rs +++ b/rclrust/src/time.rs @@ -1,5 +1,4 @@ -use std::convert::TryInto; -use std::time::Duration; +use std::{convert::TryInto, time::Duration}; use rclrust_msg::builtin_interfaces; diff --git a/rclrust/src/timer.rs b/rclrust/src/timer.rs index 04e37da1..73364a1c 100644 --- a/rclrust/src/timer.rs +++ b/rclrust/src/timer.rs @@ -1,15 +1,19 @@ -use std::convert::TryInto; -use std::sync::{Arc, Mutex}; -use std::time::Duration; +use std::{ + convert::TryInto, + sync::{Arc, Mutex}, + time::Duration, +}; use anyhow::{Context, Result}; -use crate::clock::{Clock, ClockType}; -use crate::context::RclContext; -use crate::error::ToRclRustResult; -use crate::log::Logger; -use crate::node::Node; -use crate::rclrust_error; +use crate::{ + clock::{Clock, ClockType}, + context::RclContext, + error::ToRclRustResult, + log::Logger, + node::Node, + rclrust_error, +}; #[derive(Debug)] pub struct RclTimer(Box); diff --git a/rclrust/src/utility.rs b/rclrust/src/utility.rs index f5c54961..df78dd07 100644 --- a/rclrust/src/utility.rs +++ b/rclrust/src/utility.rs @@ -2,8 +2,7 @@ use std::sync::Arc; use anyhow::Result; -use crate::context::Context; -use crate::init_options::InitOptions; +use crate::{context::Context, init_options::InitOptions}; /// Initialize rclrust context /// diff --git a/rclrust/src/wait_set.rs b/rclrust/src/wait_set.rs index 6ccdc74c..725a3345 100644 --- a/rclrust/src/wait_set.rs +++ b/rclrust/src/wait_set.rs @@ -1,13 +1,9 @@ use anyhow::{Context, Result}; -use crate::client::RclClient; -use crate::context::RclContext; -use crate::error::ToRclRustResult; -use crate::log::Logger; -use crate::rclrust_error; -use crate::service::RclService; -use crate::subscription::RclSubscription; -use crate::timer::RclTimer; +use crate::{ + client::RclClient, context::RclContext, error::ToRclRustResult, log::Logger, rclrust_error, + service::RclService, subscription::RclSubscription, timer::RclTimer, +}; #[derive(Debug)] pub(crate) struct RclWaitSet(rcl_sys::rcl_wait_set_t); diff --git a/rustfmt.toml b/rustfmt.toml index b809d0ff..94bf1452 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,3 @@ format_code_in_doc_comments = true group_imports = "StdExternalCrate" +imports_granularity = "Crate" From fa537d952d44ddfab9306ab760d5e6cdd4d47179 Mon Sep 17 00:00:00 2001 From: Yuma Hiramatsu Date: Sun, 22 Aug 2021 02:50:29 +0900 Subject: [PATCH 4/9] Set imports_layout "HorizontalVertical" --- rclrust-msg-gen/src/parser/types.rs | 3 ++- rclrust/examples/logger.rs | 8 +++++++- rclrust/src/clock.rs | 6 +++++- rclrust/src/parameter/mod.rs | 7 +++++-- rclrust/src/parameter/parameters.rs | 7 ++++++- rclrust/src/wait_set.rs | 10 ++++++++-- rustfmt.toml | 1 + 7 files changed, 34 insertions(+), 8 deletions(-) diff --git a/rclrust-msg-gen/src/parser/types.rs b/rclrust-msg-gen/src/parser/types.rs index c761ea04..9d09fed5 100644 --- a/rclrust-msg-gen/src/parser/types.rs +++ b/rclrust-msg-gen/src/parser/types.rs @@ -15,7 +15,8 @@ use super::{ use crate::types::{ primitives::*, sequences::{Array, BoundedSequence, PrimitiveArray, Sequence}, - ConstantType, MemberType, + ConstantType, + MemberType, }; pub fn parse_member_type(s: &str) -> IResult<&str, MemberType> { diff --git a/rclrust/examples/logger.rs b/rclrust/examples/logger.rs index 451156ce..a9ff7029 100644 --- a/rclrust/examples/logger.rs +++ b/rclrust/examples/logger.rs @@ -1,6 +1,12 @@ use anyhow::Result; use rclrust::{ - rclrust_debug, rclrust_error, rclrust_fatal, rclrust_info, rclrust_warn, Clock, Logger, + rclrust_debug, + rclrust_error, + rclrust_fatal, + rclrust_info, + rclrust_warn, + Clock, + Logger, }; use rclrust_msg::geometry_msgs::msg::Twist; diff --git a/rclrust/src/clock.rs b/rclrust/src/clock.rs index d8ec6944..a9d1c8a5 100644 --- a/rclrust/src/clock.rs +++ b/rclrust/src/clock.rs @@ -3,7 +3,11 @@ use std::mem::MaybeUninit; use anyhow::{ensure, Context, Result}; use crate::{ - error::ToRclRustResult, impl_from_trait_for_enum, log::Logger, rclrust_error, time::Time, + error::ToRclRustResult, + impl_from_trait_for_enum, + log::Logger, + rclrust_error, + time::Time, }; /// Time source type, used to indicate the source of a time measurement. diff --git a/rclrust/src/parameter/mod.rs b/rclrust/src/parameter/mod.rs index aaa3efee..8f400716 100644 --- a/rclrust/src/parameter/mod.rs +++ b/rclrust/src/parameter/mod.rs @@ -8,8 +8,11 @@ use std::fmt; pub(crate) use parameters::Parameters; pub(crate) use rcl_params::RclParams; pub(crate) use rclrust_msg::rcl_interfaces::msg::{ - Parameter as RclParameter, ParameterDescriptor, ParameterType as RclParameterType, - ParameterValue as RclParameterValue, SetParametersResult, + Parameter as RclParameter, + ParameterDescriptor, + ParameterType as RclParameterType, + ParameterValue as RclParameterValue, + SetParametersResult, }; pub use type_::ParameterType; pub use value::ParameterValue; diff --git a/rclrust/src/parameter/parameters.rs b/rclrust/src/parameter/parameters.rs index c126d20d..7e7ca5ba 100644 --- a/rclrust/src/parameter/parameters.rs +++ b/rclrust/src/parameter/parameters.rs @@ -3,7 +3,12 @@ use std::{collections::HashMap, sync::Mutex}; use anyhow::Result; use super::{ - Parameter, ParameterDescriptor, ParameterType, ParameterValue, RclParams, SetParametersResult, + Parameter, + ParameterDescriptor, + ParameterType, + ParameterValue, + RclParams, + SetParametersResult, }; use crate::{context::RclContext, error::RclRustError, node::RclNode}; diff --git a/rclrust/src/wait_set.rs b/rclrust/src/wait_set.rs index 725a3345..91beede2 100644 --- a/rclrust/src/wait_set.rs +++ b/rclrust/src/wait_set.rs @@ -1,8 +1,14 @@ use anyhow::{Context, Result}; use crate::{ - client::RclClient, context::RclContext, error::ToRclRustResult, log::Logger, rclrust_error, - service::RclService, subscription::RclSubscription, timer::RclTimer, + client::RclClient, + context::RclContext, + error::ToRclRustResult, + log::Logger, + rclrust_error, + service::RclService, + subscription::RclSubscription, + timer::RclTimer, }; #[derive(Debug)] diff --git a/rustfmt.toml b/rustfmt.toml index 94bf1452..c2c301b3 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,4 @@ format_code_in_doc_comments = true group_imports = "StdExternalCrate" imports_granularity = "Crate" +imports_layout = "HorizontalVertical" From ac1d4ea3acf3ee27fdf9960a2219102ef838939d Mon Sep 17 00:00:00 2001 From: Yuma Hiramatsu Date: Sun, 22 Aug 2021 02:51:40 +0900 Subject: [PATCH 5/9] Set other options --- rustfmt.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rustfmt.toml b/rustfmt.toml index c2c301b3..69597cd7 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -2,3 +2,5 @@ format_code_in_doc_comments = true group_imports = "StdExternalCrate" imports_granularity = "Crate" imports_layout = "HorizontalVertical" +unstable_features = true +use_field_init_shorthand = true From bc26f3291be14f642c3be2b3689be433af640ff5 Mon Sep 17 00:00:00 2001 From: Yuma Hiramatsu Date: Sun, 22 Aug 2021 12:41:22 +0900 Subject: [PATCH 6/9] Revert "Set imports_layout "HorizontalVertical"" This reverts commit fa537d952d44ddfab9306ab760d5e6cdd4d47179. --- rclrust-msg-gen/src/parser/types.rs | 3 +-- rclrust/examples/logger.rs | 8 +------- rclrust/src/clock.rs | 6 +----- rclrust/src/parameter/mod.rs | 7 ++----- rclrust/src/parameter/parameters.rs | 7 +------ rclrust/src/wait_set.rs | 10 ++-------- rustfmt.toml | 1 - 7 files changed, 8 insertions(+), 34 deletions(-) diff --git a/rclrust-msg-gen/src/parser/types.rs b/rclrust-msg-gen/src/parser/types.rs index 9d09fed5..c761ea04 100644 --- a/rclrust-msg-gen/src/parser/types.rs +++ b/rclrust-msg-gen/src/parser/types.rs @@ -15,8 +15,7 @@ use super::{ use crate::types::{ primitives::*, sequences::{Array, BoundedSequence, PrimitiveArray, Sequence}, - ConstantType, - MemberType, + ConstantType, MemberType, }; pub fn parse_member_type(s: &str) -> IResult<&str, MemberType> { diff --git a/rclrust/examples/logger.rs b/rclrust/examples/logger.rs index a9ff7029..451156ce 100644 --- a/rclrust/examples/logger.rs +++ b/rclrust/examples/logger.rs @@ -1,12 +1,6 @@ use anyhow::Result; use rclrust::{ - rclrust_debug, - rclrust_error, - rclrust_fatal, - rclrust_info, - rclrust_warn, - Clock, - Logger, + rclrust_debug, rclrust_error, rclrust_fatal, rclrust_info, rclrust_warn, Clock, Logger, }; use rclrust_msg::geometry_msgs::msg::Twist; diff --git a/rclrust/src/clock.rs b/rclrust/src/clock.rs index a9d1c8a5..d8ec6944 100644 --- a/rclrust/src/clock.rs +++ b/rclrust/src/clock.rs @@ -3,11 +3,7 @@ use std::mem::MaybeUninit; use anyhow::{ensure, Context, Result}; use crate::{ - error::ToRclRustResult, - impl_from_trait_for_enum, - log::Logger, - rclrust_error, - time::Time, + error::ToRclRustResult, impl_from_trait_for_enum, log::Logger, rclrust_error, time::Time, }; /// Time source type, used to indicate the source of a time measurement. diff --git a/rclrust/src/parameter/mod.rs b/rclrust/src/parameter/mod.rs index 8f400716..aaa3efee 100644 --- a/rclrust/src/parameter/mod.rs +++ b/rclrust/src/parameter/mod.rs @@ -8,11 +8,8 @@ use std::fmt; pub(crate) use parameters::Parameters; pub(crate) use rcl_params::RclParams; pub(crate) use rclrust_msg::rcl_interfaces::msg::{ - Parameter as RclParameter, - ParameterDescriptor, - ParameterType as RclParameterType, - ParameterValue as RclParameterValue, - SetParametersResult, + Parameter as RclParameter, ParameterDescriptor, ParameterType as RclParameterType, + ParameterValue as RclParameterValue, SetParametersResult, }; pub use type_::ParameterType; pub use value::ParameterValue; diff --git a/rclrust/src/parameter/parameters.rs b/rclrust/src/parameter/parameters.rs index 7e7ca5ba..c126d20d 100644 --- a/rclrust/src/parameter/parameters.rs +++ b/rclrust/src/parameter/parameters.rs @@ -3,12 +3,7 @@ use std::{collections::HashMap, sync::Mutex}; use anyhow::Result; use super::{ - Parameter, - ParameterDescriptor, - ParameterType, - ParameterValue, - RclParams, - SetParametersResult, + Parameter, ParameterDescriptor, ParameterType, ParameterValue, RclParams, SetParametersResult, }; use crate::{context::RclContext, error::RclRustError, node::RclNode}; diff --git a/rclrust/src/wait_set.rs b/rclrust/src/wait_set.rs index 91beede2..725a3345 100644 --- a/rclrust/src/wait_set.rs +++ b/rclrust/src/wait_set.rs @@ -1,14 +1,8 @@ use anyhow::{Context, Result}; use crate::{ - client::RclClient, - context::RclContext, - error::ToRclRustResult, - log::Logger, - rclrust_error, - service::RclService, - subscription::RclSubscription, - timer::RclTimer, + client::RclClient, context::RclContext, error::ToRclRustResult, log::Logger, rclrust_error, + service::RclService, subscription::RclSubscription, timer::RclTimer, }; #[derive(Debug)] diff --git a/rustfmt.toml b/rustfmt.toml index 69597cd7..66d00f8f 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,6 +1,5 @@ format_code_in_doc_comments = true group_imports = "StdExternalCrate" imports_granularity = "Crate" -imports_layout = "HorizontalVertical" unstable_features = true use_field_init_shorthand = true From c613af3c757269d09f331990efff7169e1265960 Mon Sep 17 00:00:00 2001 From: Yuma Hiramatsu Date: Sun, 22 Aug 2021 12:59:08 +0900 Subject: [PATCH 7/9] Update CI --- .github/workflows/foxy.yaml | 25 ++++++++++------------- .github/workflows/lint.yaml | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/lint.yaml diff --git a/.github/workflows/foxy.yaml b/.github/workflows/foxy.yaml index 18561cec..4ed111c8 100644 --- a/.github/workflows/foxy.yaml +++ b/.github/workflows/foxy.yaml @@ -13,6 +13,11 @@ jobs: test: strategy: matrix: + rust: + - stable + - beta + - nightly + include: - os: ubuntu-20.04 ros_distro: foxy @@ -22,13 +27,12 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Install stable toolchain + - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable + toolchain: ${{ matrix.rust }} override: true - components: rustfmt, clippy - name: Setup ROS environment uses: ros-tooling/setup-ros@v0.2 @@ -37,22 +41,13 @@ jobs: - name: Run cargo check run: | - source /opt/ros/foxy/setup.bash + source /opt/ros/${{ matrix.ros_distro }}/setup.bash cargo check --all-features - name: Run cargo test # for skip rcl-sys run: | - source /opt/ros/foxy/setup.bash + source /opt/ros/${{ matrix.ros_distro }}/setup.bash cargo test -p rclrust-msg rclrust-msg-gen cargo test -p rclrust -- --test-threads 1 - - - name: Run cargo fmt - run: | - source /opt/ros/foxy/setup.bash - cargo fmt -- --check - - - name: Run cargo clippy - run: | - source /opt/ros/foxy/setup.bash - cargo clippy -- -D warnings + continue-on-error: ${{ matrix.rust == 'nightly' }} diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 00000000..d88459d8 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,40 @@ +name: Lint + +on: + push: + branches: main + pull_request: + branches: main + +env: + CARGO_TERM_COLOR: always + +jobs: + lint: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: rustfmt, clippy + + - name: Setup ROS environment + uses: ros-tooling/setup-ros@v0.2 + with: + required-ros-distributions: foxy + + - name: Run cargo fmt + run: | + source /opt/ros/foxy/setup.bash + cargo fmt -- --check + + - name: Run cargo clippy + run: | + source /opt/ros/foxy/setup.bash + cargo clippy -- -D warnings From 1c82926a43eef32d8c70b9bb23b43a9b48fe7396 Mon Sep 17 00:00:00 2001 From: Yuma Hiramatsu Date: Sun, 22 Aug 2021 13:28:33 +0900 Subject: [PATCH 8/9] Remove trailing semicolon --- rclrust/src/log.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rclrust/src/log.rs b/rclrust/src/log.rs index b1b7c693..1f25cfd7 100644 --- a/rclrust/src/log.rs +++ b/rclrust/src/log.rs @@ -183,35 +183,35 @@ impl Logger { #[macro_export] macro_rules! rclrust_debug { ($logger:expr, $($arg:tt)+) => { - $logger.log_common($crate::log::LogSeverity::Debug, &format!($($arg)+), file!(), line!()); + $logger.log_common($crate::log::LogSeverity::Debug, &format!($($arg)+), file!(), line!()) }; } #[macro_export] macro_rules! rclrust_info { ($logger:expr, $($arg:tt)+) => { - $logger.log_common($crate::log::LogSeverity::Info, &format!($($arg)+), file!(), line!()); + $logger.log_common($crate::log::LogSeverity::Info, &format!($($arg)+), file!(), line!()) }; } #[macro_export] macro_rules! rclrust_warn { ($logger:expr, $($arg:tt)+) => { - $logger.log_common($crate::log::LogSeverity::Warn, &format!($($arg)+), file!(), line!()); + $logger.log_common($crate::log::LogSeverity::Warn, &format!($($arg)+), file!(), line!()) }; } #[macro_export] macro_rules! rclrust_error { ($logger:expr, $($arg:tt)+) => { - $logger.log_common($crate::log::LogSeverity::Error, &format!($($arg)+), file!(), line!()); + $logger.log_common($crate::log::LogSeverity::Error, &format!($($arg)+), file!(), line!()) }; } #[macro_export] macro_rules! rclrust_fatal { ($logger:expr, $($arg:tt)+) => { - $logger.log_common($crate::log::LogSeverity::Fatal, &format!($($arg)+), file!(), line!()); + $logger.log_common($crate::log::LogSeverity::Fatal, &format!($($arg)+), file!(), line!()) }; } From eb48a6a27742f03af3bd0ed8d088c6f2cd5e5219 Mon Sep 17 00:00:00 2001 From: Yuma Hiramatsu Date: Sun, 22 Aug 2021 13:29:42 +0900 Subject: [PATCH 9/9] Split CI job --- .github/workflows/lint.yaml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index d88459d8..8adb3ff9 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -10,7 +10,7 @@ env: CARGO_TERM_COLOR: always jobs: - lint: + format: runs-on: ubuntu-20.04 steps: @@ -20,9 +20,9 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly + toolchain: stable override: true - components: rustfmt, clippy + components: rustfmt - name: Setup ROS environment uses: ros-tooling/setup-ros@v0.2 @@ -34,6 +34,25 @@ jobs: source /opt/ros/foxy/setup.bash cargo fmt -- --check + lint: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: clippy + + - name: Setup ROS environment + uses: ros-tooling/setup-ros@v0.2 + with: + required-ros-distributions: foxy + - name: Run cargo clippy run: | source /opt/ros/foxy/setup.bash