| @@ -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' }} | |||
| @@ -0,0 +1,59 @@ | |||
| name: Lint | |||
| on: | |||
| push: | |||
| branches: main | |||
| pull_request: | |||
| branches: main | |||
| env: | |||
| CARGO_TERM_COLOR: always | |||
| jobs: | |||
| format: | |||
| runs-on: ubuntu-20.04 | |||
| steps: | |||
| - uses: actions/checkout@v2 | |||
| - name: Install Rust toolchain | |||
| uses: actions-rs/toolchain@v1 | |||
| with: | |||
| profile: minimal | |||
| toolchain: stable | |||
| override: true | |||
| components: rustfmt | |||
| - 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 | |||
| 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 | |||
| cargo clippy -- -D warnings | |||
| @@ -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"; | |||
| @@ -59,13 +57,10 @@ fn parse_action_string(pkg_name: &str, action_name: &str, action_string: &str) - | |||
| #[cfg(test)] | |||
| mod test { | |||
| use super::*; | |||
| use std::path::PathBuf; | |||
| use crate::types::primitives::*; | |||
| use crate::types::sequences::*; | |||
| use crate::types::MemberType; | |||
| use super::*; | |||
| use crate::types::{primitives::*, sequences::*, MemberType}; | |||
| fn parse_action_def(srv_name: &str) -> Result<Action> { | |||
| let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) | |||
| @@ -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<Vec<String>> { | |||
| match r#type { | |||
| @@ -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) | |||
| @@ -46,9 +48,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"); | |||
| @@ -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}; | |||
| @@ -204,9 +204,10 @@ pub fn string_literal_sequence(s: &str) -> IResult<&str, Vec<String>> { | |||
| #[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); | |||
| @@ -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<Vec<String>> { | |||
| match nestable_type { | |||
| @@ -102,9 +102,10 @@ pub fn member_def(line: &str) -> Result<Member> { | |||
| #[cfg(test)] | |||
| mod test { | |||
| use anyhow::Result; | |||
| use super::*; | |||
| use crate::types::primitives::BasicType; | |||
| use anyhow::Result; | |||
| #[test] | |||
| fn parse_member_def() -> Result<()> { | |||
| @@ -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>) { | |||
| @@ -59,13 +57,11 @@ pub fn parse_message_string( | |||
| #[cfg(test)] | |||
| mod test { | |||
| use super::*; | |||
| use crate::types::primitives::*; | |||
| use crate::types::sequences::*; | |||
| use crate::types::*; | |||
| use std::path::PathBuf; | |||
| use super::*; | |||
| use crate::types::{primitives::*, sequences::*, *}; | |||
| #[test] | |||
| fn test_split_once() { | |||
| assert_eq!(split_once("abc", 'b'), ("a", Some("c"))); | |||
| @@ -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"; | |||
| @@ -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"; | |||
| @@ -53,10 +51,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<Service> { | |||
| let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) | |||
| .join(format!("test_msgs/srv/{}.srv", srv_name)); | |||
| @@ -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( | |||
| @@ -146,9 +152,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()); | |||
| @@ -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)] | |||
| @@ -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) => { | |||
| @@ -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) => { | |||
| @@ -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)] | |||
| @@ -1,5 +1,4 @@ | |||
| use std::mem::ManuallyDrop; | |||
| use std::ops::Deref; | |||
| use std::{mem::ManuallyDrop, ops::Deref}; | |||
| use super::traits::{FFIFromRust, FFIToRust}; | |||
| @@ -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}; | |||
| @@ -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; | |||
| @@ -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<()> { | |||
| @@ -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<()> { | |||
| @@ -1,7 +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()?; | |||
| @@ -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<()> { | |||
| @@ -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()?; | |||
| @@ -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<()> { | |||
| @@ -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; | |||
| @@ -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<rcl_sys::rcl_client_t>); | |||
| @@ -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)] | |||
| @@ -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<rcl_sys::rcl_context_t>); | |||
| @@ -178,7 +181,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>( | |||
| @@ -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<Node<'_>>) -> Result<()> { | |||
| let mut exec = SingleThreadExecutor::new(node.context)?; | |||
| @@ -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); | |||
| @@ -42,16 +40,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<Self> { | |||
| Ok(Self { | |||
| options: RclInitOptions::new()?, | |||
| // shutdown_on_sigint: true, | |||
| // initialize_logging: true, | |||
| /* shutdown_on_sigint: true, | |||
| * initialize_logging: true, */ | |||
| }) | |||
| } | |||
| @@ -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<Self>; | |||
| @@ -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 { | |||
| @@ -179,43 +183,44 @@ 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!()) | |||
| }; | |||
| } | |||
| #[cfg(test)] | |||
| mod test { | |||
| use super::*; | |||
| use std::sync::Mutex; | |||
| use super::*; | |||
| static TEST_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(())); | |||
| #[test] | |||
| @@ -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<rcl_sys::rcl_node_t>); | |||
| @@ -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); | |||
| @@ -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 { | |||
| @@ -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>); | |||
| @@ -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<rcl_sys::rcl_publisher_t>); | |||
| @@ -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)] | |||
| @@ -158,7 +157,7 @@ impl QoSProfile { | |||
| /// # Examples | |||
| /// | |||
| /// ``` | |||
| /// use rclrust::qos::{QoSProfile, HistoryPolicy}; | |||
| /// use rclrust::qos::{HistoryPolicy, QoSProfile}; | |||
| /// | |||
| /// let qos = QoSProfile::system_default().history(HistoryPolicy::KeepAll); | |||
| /// ``` | |||
| @@ -242,7 +241,7 @@ impl QoSProfile { | |||
| /// # Examples | |||
| /// | |||
| /// ``` | |||
| /// use rclrust::qos::{QoSProfile, DurabilityPolicy}; | |||
| /// use rclrust::qos::{DurabilityPolicy, QoSProfile}; | |||
| /// | |||
| /// let qos = QoSProfile::system_default().durability(DurabilityPolicy::Volatile); | |||
| /// ``` | |||
| @@ -283,6 +282,7 @@ impl QoSProfile { | |||
| /// | |||
| /// ``` | |||
| /// use std::time::Duration; | |||
| /// | |||
| /// use rclrust::qos::QoSProfile; | |||
| /// | |||
| /// let qos = QoSProfile::system_default().deadline(Duration::new(5, 0)); | |||
| @@ -298,6 +298,7 @@ impl QoSProfile { | |||
| /// | |||
| /// ``` | |||
| /// use std::time::Duration; | |||
| /// | |||
| /// use rclrust::qos::QoSProfile; | |||
| /// | |||
| /// let qos = QoSProfile::system_default().lifespan(Duration::new(5, 0)); | |||
| @@ -312,7 +313,7 @@ impl QoSProfile { | |||
| /// # Examples | |||
| /// | |||
| /// ``` | |||
| /// use rclrust::qos::{QoSProfile, LivelinessPolicy}; | |||
| /// use rclrust::qos::{LivelinessPolicy, QoSProfile}; | |||
| /// | |||
| /// let qos = QoSProfile::system_default().liveliness(LivelinessPolicy::Automatic); | |||
| /// ``` | |||
| @@ -327,6 +328,7 @@ impl QoSProfile { | |||
| /// | |||
| /// ``` | |||
| /// use std::time::Duration; | |||
| /// | |||
| /// use rclrust::qos::QoSProfile; | |||
| /// | |||
| /// let qos = QoSProfile::system_default().liveliness_lease_duration(Duration::new(5, 0)); | |||
| @@ -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<rcl_sys::rcl_service_t>); | |||
| @@ -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<rcl_sys::rcl_subscription_t>); | |||
| @@ -1,5 +1,4 @@ | |||
| use std::convert::TryInto; | |||
| use std::time::Duration; | |||
| use std::{convert::TryInto, time::Duration}; | |||
| use rclrust_msg::builtin_interfaces; | |||
| @@ -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<rcl_sys::rcl_timer_t>); | |||
| @@ -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 | |||
| /// | |||
| @@ -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); | |||
| @@ -0,0 +1,5 @@ | |||
| format_code_in_doc_comments = true | |||
| group_imports = "StdExternalCrate" | |||
| imports_granularity = "Crate" | |||
| unstable_features = true | |||
| use_field_init_shorthand = true | |||