diff --git a/.github/workflows/rust-minimal.yml b/.github/workflows/rust-minimal.yml index 1a9e8175d..06480d800 100644 --- a/.github/workflows/rust-minimal.yml +++ b/.github/workflows/rust-minimal.yml @@ -69,11 +69,12 @@ jobs: # Colcon can not be run in a venv which is required in Ubuntu Noble # Removing the externally managed file - - name: Install colcon-cargo and colcon-ros-cargo + - name: Install colcon-cargo, colcon-ros-cargo, and cargo-ament-build run: | sudo rm -f /usr/lib/python3.12/EXTERNALLY-MANAGED sudo pip3 install git+https://github.com/colcon/colcon-cargo.git sudo pip3 install git+https://github.com/colcon/colcon-ros-cargo.git + cargo install --git https://git@github.com/maspe36/cargo-ament-build.git --branch feature/skip_reexport_marker_file - name: Check formatting of Rust packages run: | diff --git a/.github/workflows/rust-stable.yml b/.github/workflows/rust-stable.yml index 707e2b7e4..9567ed8cc 100644 --- a/.github/workflows/rust-stable.yml +++ b/.github/workflows/rust-stable.yml @@ -69,11 +69,12 @@ jobs: # Colcon can not be run in a venv which is required in Ubuntu Noble # Removing the externally managed file - - name: Install colcon-cargo and colcon-ros-cargo + - name: Install colcon-cargo, colcon-ros-cargo, and cargo-ament-build run: | sudo rm -f /usr/lib/python3.12/EXTERNALLY-MANAGED sudo pip3 install git+https://github.com/colcon/colcon-cargo.git sudo pip3 install git+https://github.com/colcon/colcon-ros-cargo.git + cargo install --git https://git@github.com/maspe36/cargo-ament-build.git --branch feature/skip_reexport_marker_file - name: Check formatting of Rust packages run: | diff --git a/.github/workflows/rust-win.yml b/.github/workflows/rust-win.yml index 434b75e76..70c3155a6 100644 --- a/.github/workflows/rust-win.yml +++ b/.github/workflows/rust-win.yml @@ -40,6 +40,8 @@ jobs: # prerequisites and fixes for windows build ros2_rust: # * Libclang has to be added (from the ros2_rust instructions) and the dll has to be renamed # * colcon-ros-cargo and colcon-cargo have to be added as PyPI packages + # * cargo-ament-build is manually installed from github for now to include the change to skip + # installing the marker file if the package should be reexported run: | pixi add libclang --manifest-path C:\pixi_ws\pixi.toml $src = "C:\pixi_ws\.pixi\envs\default\Library\bin\libclang-13.dll" @@ -48,6 +50,7 @@ jobs: pixi add --pypi "colcon-ros-cargo@git+https://github.com/colcon/colcon-ros-cargo.git" --manifest-path C:\pixi_ws\pixi.toml pixi add --pypi "colcon-cargo@git+https://github.com/colcon/colcon-cargo.git" --manifest-path C:\pixi_ws\pixi.toml pixi upgrade colcon-core --manifest-path C:\pixi_ws\pixi.toml + cargo install --git https://git@github.com/maspe36/cargo-ament-build.git --branch feature/skip_reexport_marker_file - name: Get prebuilt ROS files and unzip run: | diff --git a/docs/writing-your-first-rclrs-node.md b/docs/writing-your-first-rclrs-node.md index 8dbd8d2fa..f8f1d4487 100644 --- a/docs/writing-your-first-rclrs-node.md +++ b/docs/writing-your-first-rclrs-node.md @@ -44,7 +44,7 @@ Instead, you can store the node as a regular member. Let's add a struct that con ```rust use std::sync::Arc; -use std_msgs::msg::String as StringMsg; +use rclrs::std_msgs::msg::String as StringMsg; struct RepublisherNode { node: Arc, @@ -111,7 +111,7 @@ So, to store the received data in the struct, the following things have to chang ```rust use std::sync::{Arc, Mutex}; // (1) -use std_msgs::msg::String as StringMsg; +use rclrs::std_msgs::msg::String as StringMsg; struct RepublisherNode { node: Arc, diff --git a/docs/writing_a_simple_publisher_and_subscriber.md b/docs/writing_a_simple_publisher_and_subscriber.md index 55e3a9284..1e2d32271 100644 --- a/docs/writing_a_simple_publisher_and_subscriber.md +++ b/docs/writing_a_simple_publisher_and_subscriber.md @@ -94,7 +94,7 @@ To construct a node, replace the code in your `main.rs` file with the following: /// methods to publish a simple "Hello World" message on a loop in separate threads. use rclrs::{create_node, Context, Node, Publisher, RclrsError, QOS_PROFILE_DEFAULT}; use std::{env, sync::Arc, thread, time::Duration}; -use std_msgs::msg::String as StringMsg; +use rclrs::std_msgs::msg::String as StringMsg; /// SimplePublisherNode struct contains node and publisher members. /// Used to initialize a ROS 2 node and publisher, and publish messages. struct SimplePublisherNode { @@ -138,7 +138,7 @@ handling, iteration, threading, ROS 2 communication, and string message publishi ```rust use rclrs::{create_node, Context, Node, Publisher, RclrsError, QOS_PROFILE_DEFAULT}; use std::{env, sync::Arc, thread, time::Duration}; -use std_msgs::msg::String as StringMsg; +use rclrs::std_msgs::msg::String as StringMsg; ``` * `use std::{sync::Arc, time::Duration, iter, thread};`: Imports specific features from the standard library: - `Arc` is for thread-safe shared ownership of data. @@ -149,7 +149,7 @@ use std_msgs::msg::String as StringMsg; - `RclrsError` for handling errors. - `QOS_PROFILE_DEFAULT` for default Quality of Service settings. - `Context, create_node, Node, Publisher` are for ROS 2 node creation and publishing. -* `use std_msgs::msg::String as StringMsg;`: Imports the `StringMsg` type for publishing string messages. +* `use rclrs::std_msgs::msg::String as StringMsg;`: Imports the `StringMsg` type for publishing string messages. #### `SimplePublisherNode` Next, this structure defines a `SimplePublisherNode` which holds references to a ROS 2 node and a publisher for string messages. @@ -291,7 +291,7 @@ use std::{ thread, time::Duration, }; -use std_msgs::msg::String as StringMsg; +use rclrs::std_msgs::msg::String as StringMsg; pub struct SimpleSubscriptionNode { node: Arc, _subscriber: Arc>, diff --git a/rclrs/Cargo.toml b/rclrs/Cargo.toml index 8692e19ab..05a658f42 100644 --- a/rclrs/Cargo.toml +++ b/rclrs/Cargo.toml @@ -35,6 +35,8 @@ async-std = "1.13" # Needed for dynamic messages libloading = "0.8" +ros-env = "0.1" + # Needed for the Message trait, among others rosidl_runtime_rs = "0.6" @@ -54,6 +56,8 @@ tokio-stream = "0.1" # Needed by action clients to generate UUID values for their goals uuid = { version = "1", features = ["v4"] } +paste = { version = "1", optional = true} + [dev-dependencies] # Needed for e.g. writing yaml files in tests tempfile = "3.3.0" @@ -65,12 +69,15 @@ tokio = { version = "1", features = ["rt", "time", "macros"] } cfg-if = "1.0.0" rustflags = "0.1" +# Helper crate for working with AMENT_PREFIX_PATH +ament_rs = "0.3" + [features] default = [] -serde = ["dep:serde", "dep:serde-big-array", "rosidl_runtime_rs/serde"] +serde = ["dep:serde", "dep:serde-big-array", "rosidl_runtime_rs/serde", "ros-env/serde"] # This feature is solely for the purpose of being able to generate documetation without a ROS installation # The only intended usage of this feature is for docs.rs builders to work, and is not intended to be used by end users -use_ros_shim = ["rosidl_runtime_rs/use_ros_shim"] +use_ros_shim = ["paste", "rosidl_runtime_rs/use_ros_shim"] [package.metadata.docs.rs] features = ["use_ros_shim"] diff --git a/rclrs/build.rs b/rclrs/build.rs index 9cdb375df..ff0849416 100644 --- a/rclrs/build.rs +++ b/rclrs/build.rs @@ -1,63 +1,52 @@ -use std::{env, path::Path}; -const AMENT_PREFIX_PATH: &str = "AMENT_PREFIX_PATH"; +use ament_rs::search_paths::get_search_paths; +use std::{env, path::PathBuf}; + const ROS_DISTRO: &str = "ROS_DISTRO"; +const KNOWN_DISTROS: &[&str] = &["humble", "jazzy", "kilted", "rolling"]; -fn get_env_var_or_abort(env_var: &'static str) -> String { - if let Ok(value) = env::var(env_var) { - value - } else { - panic!( - "{} environment variable not set - please source ROS 2 installation first.", - env_var - ); - } +fn get_ros_distro() -> String { + env::var(ROS_DISTRO) + .or_else(|_| { + if env::var("CARGO_FEATURE_USE_ROS_SHIM").is_ok() { + rustflags::from_env() + .find_map(|f| match f { + rustflags::Flag::Cfg { name, value } if name.as_str() == "ros_distro" => { + value + } + _ => None, + }) + .ok_or_else(|| "Missing --cfg ros_distro in RUSTFLAGS".to_string()) + } else { + Err(format!("Set {ROS_DISTRO} or use ROS shim")) + } + }) + .expect("Failed to determine ROS distro") } fn main() { println!( "cargo:rustc-check-cfg=cfg(ros_distro, values(\"{}\"))", - ["humble", "jazzy", "kilted", "rolling"].join("\", \"") + KNOWN_DISTROS.join("\", \"") ); - let ros_distro = if let Ok(value) = env::var(ROS_DISTRO) { - value - } else { - cfg_if::cfg_if! { - if #[cfg(feature="use_ros_shim")] { - use rustflags; - // // Look for --cfg ros_distro= - for flag in rustflags::from_env() { - if matches!(flag, rustflags::Flag::Cfg { ref name, value : _ } if name == "ros_distro") { - if let rustflags::Flag::Cfg {name:_, value: flag_value} = flag { - println!("cargo:rustc-cfg=ros_distro=\"{}\"", flag_value.unwrap()); - return; - } else { - continue; - } - } - } - let error_msg = - "When using the use_ros_shim feature, you must pass the ROS distribution you are targeting as a compiler flag with --cfg ros_distro=\"\""; - panic!("{}", error_msg); - } else { - let error_msg = - "ROS_DISTRO environment variable not set - please source ROS 2 installation first."; - panic!("{}", error_msg); - } - } - }; - println!("cargo:rustc-cfg=ros_distro=\"{ros_distro}\""); + println!("cargo:rustc-cfg=ros_distro=\"{}\"", get_ros_distro()); + println!("cargo:rerun-if-env-changed={ROS_DISTRO}"); + + let ament_prefix_paths = get_search_paths().unwrap_or_default(); - let ament_prefix_paths = get_env_var_or_abort(AMENT_PREFIX_PATH); - for ament_prefix_path in ament_prefix_paths.split(':').map(Path::new) { + for ament_prefix_path in &ament_prefix_paths { // Link the native libraries - let library_path = ament_prefix_path.join("lib"); + let library_path = PathBuf::from(ament_prefix_path).join("lib"); println!("cargo:rustc-link-search=native={}", library_path.display()); } - println!("cargo:rustc-link-lib=dylib=rcl"); - println!("cargo:rustc-link-lib=dylib=rcl_action"); - println!("cargo:rustc-link-lib=dylib=rcl_yaml_param_parser"); - println!("cargo:rustc-link-lib=dylib=rcutils"); - println!("cargo:rustc-link-lib=dylib=rmw"); - println!("cargo:rustc-link-lib=dylib=rmw_implementation"); + [ + "rcl", + "rcl_action", + "rcl_yaml_param_parser", + "rcutils", + "rmw", + "rmw_implementation", + ] + .iter() + .for_each(|lib| println!("cargo:rustc-link-lib=dylib={lib}")); } diff --git a/rclrs/src/action.rs b/rclrs/src/action.rs index 62b1543de..6e90c2e5e 100644 --- a/rclrs/src/action.rs +++ b/rclrs/src/action.rs @@ -9,7 +9,8 @@ pub use action_goal_receiver::*; pub(crate) mod action_server; pub use action_server::*; -use crate::{log_error, rcl_bindings::*, vendor::builtin_interfaces::msg::Time, DropGuard}; +use crate::{log_error, rcl_bindings::*, DropGuard}; +use ros_env::builtin_interfaces::msg::Time; use std::fmt; #[cfg(feature = "serde")] @@ -255,13 +256,11 @@ fn empty_goal_status_array() -> DropGuard { #[cfg(test)] mod tests { - use crate::{ - vendor::example_interfaces::action::{ - Fibonacci, Fibonacci_Feedback, Fibonacci_Goal, Fibonacci_Result, - }, - *, - }; + use crate::*; use futures::StreamExt; + use ros_env::example_interfaces::action::{ + Fibonacci, Fibonacci_Feedback, Fibonacci_Goal, Fibonacci_Result, + }; use std::time::Duration; use tokio::sync::mpsc::unbounded_channel; diff --git a/rclrs/src/action/action_client.rs b/rclrs/src/action/action_client.rs index 78064ad42..0bbd994e6 100644 --- a/rclrs/src/action/action_client.rs +++ b/rclrs/src/action/action_client.rs @@ -1,13 +1,11 @@ use super::empty_goal_status_array; use crate::{ - log_warn, - rcl_bindings::*, - vendor::{action_msgs::srv::CancelGoal_Response, builtin_interfaces::msg::Time}, - CancelResponse, CancelResponseCode, DropGuard, GoalStatus, GoalStatusCode, GoalUuid, - MultiCancelResponse, Node, NodeHandle, QoSProfile, RclPrimitive, RclPrimitiveHandle, - RclPrimitiveKind, RclrsError, ReadyKind, TakeFailedAsNone, ToResult, Waitable, - WaitableLifecycle, ENTITY_LIFECYCLE_MUTEX, + log_warn, rcl_bindings::*, CancelResponse, CancelResponseCode, DropGuard, GoalStatus, + GoalStatusCode, GoalUuid, MultiCancelResponse, Node, NodeHandle, QoSProfile, RclPrimitive, + RclPrimitiveHandle, RclPrimitiveKind, RclrsError, ReadyKind, TakeFailedAsNone, ToResult, + Waitable, WaitableLifecycle, ENTITY_LIFECYCLE_MUTEX, }; +use ros_env::{action_msgs::srv::CancelGoal_Response, builtin_interfaces::msg::Time}; use rosidl_runtime_rs::{Action, Message, RmwFeedbackMessage, RmwGoalResponse, RmwResultResponse}; use std::{ any::Any, diff --git a/rclrs/src/action/action_client/goal_client.rs b/rclrs/src/action/action_client/goal_client.rs index 61d2773ff..f06f9d051 100644 --- a/rclrs/src/action/action_client/goal_client.rs +++ b/rclrs/src/action/action_client/goal_client.rs @@ -1,7 +1,7 @@ use crate::{ - vendor::builtin_interfaces::msg::Time, CancellationClient, FeedbackClient, GoalStatus, - GoalStatusCode, ResultClient, StatusWatcher, + CancellationClient, FeedbackClient, GoalStatus, GoalStatusCode, ResultClient, StatusWatcher, }; +use ros_env::builtin_interfaces::msg::Time; use rosidl_runtime_rs::Action; use std::{ pin::Pin, @@ -96,7 +96,7 @@ impl GoalClient { /// /// ``` /// use rclrs::*; -/// use crate::rclrs::vendor::example_interfaces::action::Fibonacci; +/// use ros_env::example_interfaces::action::Fibonacci; /// use futures::StreamExt; /// /// async fn process_goal_client_stream( diff --git a/rclrs/src/action/action_server.rs b/rclrs/src/action/action_server.rs index 599e5983b..468eff101 100644 --- a/rclrs/src/action/action_server.rs +++ b/rclrs/src/action/action_server.rs @@ -1,12 +1,12 @@ use super::empty_goal_status_array; use crate::{ - action::GoalUuid, error::ToResult, rcl_bindings::*, - vendor::action_msgs::srv::CancelGoal_Response, ActionGoalReceiver, CancelResponseCode, + action::GoalUuid, error::ToResult, rcl_bindings::*, ActionGoalReceiver, CancelResponseCode, DropGuard, GoalStatusCode, Node, NodeHandle, QoSProfile, RclPrimitive, RclPrimitiveHandle, RclPrimitiveKind, RclrsError, ReadyKind, TakeFailedAsNone, Waitable, WaitableLifecycle, ENTITY_LIFECYCLE_MUTEX, }; use futures::future::BoxFuture; +use ros_env::action_msgs::srv::CancelGoal_Response; use rosidl_runtime_rs::{Action, Message, RmwGoalRequest, RmwResultRequest}; use std::{ any::Any, diff --git a/rclrs/src/action/action_server/cancellation_state.rs b/rclrs/src/action/action_server/cancellation_state.rs index 9dc166fbe..e34c043c9 100644 --- a/rclrs/src/action/action_server/cancellation_state.rs +++ b/rclrs/src/action/action_server/cancellation_state.rs @@ -1,18 +1,16 @@ use super::ActionServerHandle; use crate::{ - log_error, - rcl_bindings::*, - vendor::{ - action_msgs::{msg::GoalInfo, srv::CancelGoal_Response}, - unique_identifier_msgs::msg::UUID, - }, - CancelResponseCode, GoalUuid, Node, RclrsErrorFilter, ToResult, + log_error, rcl_bindings::*, CancelResponseCode, GoalUuid, Node, RclrsErrorFilter, ToResult, }; use futures::{ future::{select, Either}, pin_mut, }; use futures_lite::future::race; +use ros_env::{ + action_msgs::{msg::GoalInfo, srv::CancelGoal_Response}, + unique_identifier_msgs::msg::UUID, +}; use rosidl_runtime_rs::{Action, Message}; use std::{ borrow::Cow, diff --git a/rclrs/src/client.rs b/rclrs/src/client.rs index ecf4c3795..aeb406b08 100644 --- a/rclrs/src/client.rs +++ b/rclrs/src/client.rs @@ -159,7 +159,7 @@ where /// signatures and which returns a `()` (a.k.a. nothing). /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::test_msgs; + /// # use ros_env::test_msgs; /// # let node = Context::default() /// # .create_basic_executor() /// # .create_node("test_node")?; @@ -187,7 +187,7 @@ where /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::test_msgs; + /// # use ros_env::test_msgs; /// # use std::future::Future; /// # let node = Context::default() /// # .create_basic_executor() @@ -216,7 +216,7 @@ where /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::test_msgs; + /// # use ros_env::test_msgs; /// # let node = Context::default() /// # .create_basic_executor() /// # .create_node("test_node")?; @@ -568,7 +568,8 @@ unsafe impl Send for rcl_client_t {} #[cfg(test)] mod tests { use super::*; - use crate::{test_helpers::*, vendor::test_msgs}; + use crate::test_helpers::*; + use ros_env::test_msgs; #[test] fn traits() { diff --git a/rclrs/src/dynamic_message/dynamic_publisher.rs b/rclrs/src/dynamic_message/dynamic_publisher.rs index 22cbf3268..af5ef5b22 100644 --- a/rclrs/src/dynamic_message/dynamic_publisher.rs +++ b/rclrs/src/dynamic_message/dynamic_publisher.rs @@ -1,13 +1,17 @@ -use std::ffi::CString; -use std::sync::{Arc, Mutex}; +use std::{ + ffi::CString, + sync::{Arc, Mutex}, +}; use super::{ get_type_support_handle, get_type_support_library, DynamicMessage, DynamicMessageError, DynamicMessageMetadata, MessageTypeName, }; -use crate::error::{RclrsError, ToResult}; -use crate::rcl_bindings::*; -use crate::{Node, PublisherHandle, PublisherOptions, ENTITY_LIFECYCLE_MUTEX}; +use crate::{ + error::{RclrsError, ToResult}, + rcl_bindings::*, + Node, PublisherHandle, PublisherOptions, ENTITY_LIFECYCLE_MUTEX, +}; /// Struct for sending dynamic messages. /// @@ -150,8 +154,8 @@ mod tests { #[test] fn test_dynamic_publishers() -> Result<(), RclrsError> { - use crate::vendor::test_msgs::msg; use crate::TopicEndpointInfo; + use ros_env::test_msgs::msg; let namespace = "/test_dynamic_publishers_graph"; let graph = construct_test_graph(namespace)?; diff --git a/rclrs/src/dynamic_message/dynamic_subscription.rs b/rclrs/src/dynamic_message/dynamic_subscription.rs index 350375ceb..ddc3de290 100644 --- a/rclrs/src/dynamic_message/dynamic_subscription.rs +++ b/rclrs/src/dynamic_message/dynamic_subscription.rs @@ -1,8 +1,10 @@ -use std::any::Any; -use std::boxed::Box; -use std::ffi::CString; -use std::ops::{Deref, DerefMut}; -use std::sync::{Arc, Mutex}; +use std::{ + any::Any, + boxed::Box, + ffi::CString, + ops::{Deref, DerefMut}, + sync::{Arc, Mutex}, +}; use futures::future::BoxFuture; @@ -10,11 +12,11 @@ use super::{ get_type_support_handle, get_type_support_library, DynamicMessage, DynamicMessageMetadata, MessageStructure, MessageTypeName, }; -use crate::rcl_bindings::*; use crate::{ - MessageInfo, Node, NodeHandle, RclPrimitive, RclPrimitiveHandle, RclPrimitiveKind, RclrsError, - RclrsErrorFilter, ReadyKind, SubscriptionHandle, SubscriptionOptions, ToResult, Waitable, - WaitableLifecycle, WorkScope, Worker, WorkerCommands, ENTITY_LIFECYCLE_MUTEX, + rcl_bindings::*, MessageInfo, Node, NodeHandle, RclPrimitive, RclPrimitiveHandle, + RclPrimitiveKind, RclrsError, RclrsErrorFilter, ReadyKind, SubscriptionHandle, + SubscriptionOptions, ToResult, Waitable, WaitableLifecycle, WorkScope, Worker, WorkerCommands, + ENTITY_LIFECYCLE_MUTEX, }; /// Struct for receiving messages whose type is not known at compile time. diff --git a/rclrs/src/dynamic_message/field_access.rs b/rclrs/src/dynamic_message/field_access.rs index 4ae2a5a17..bcddc0b1a 100644 --- a/rclrs/src/dynamic_message/field_access.rs +++ b/rclrs/src/dynamic_message/field_access.rs @@ -889,10 +889,7 @@ mod immutable { define_value_types!(select_immutable); } -pub use immutable::ArrayValue; -pub use immutable::BoundedSequenceValue; -pub use immutable::SequenceValue; -pub use immutable::SimpleValue; +pub use immutable::{ArrayValue, BoundedSequenceValue, SequenceValue, SimpleValue}; /// The value of a field in a [`DynamicMessage`][1]. /// @@ -944,10 +941,10 @@ mod mutable { define_value_types!(select_mutable); } -pub use mutable::ArrayValue as ArrayValueMut; -pub use mutable::BoundedSequenceValue as BoundedSequenceValueMut; -pub use mutable::SequenceValue as SequenceValueMut; -pub use mutable::SimpleValue as SimpleValueMut; +pub use mutable::{ + ArrayValue as ArrayValueMut, BoundedSequenceValue as BoundedSequenceValueMut, + SequenceValue as SequenceValueMut, SimpleValue as SimpleValueMut, +}; /// The value of a field in a [`DynamicMessage`][1]. /// diff --git a/rclrs/src/dynamic_message/field_access/dynamic_bounded_string.rs b/rclrs/src/dynamic_message/field_access/dynamic_bounded_string.rs index 431c8eb69..9e011168b 100644 --- a/rclrs/src/dynamic_message/field_access/dynamic_bounded_string.rs +++ b/rclrs/src/dynamic_message/field_access/dynamic_bounded_string.rs @@ -1,7 +1,9 @@ -use std::convert::AsMut; -use std::fmt::{self, Display}; -use std::num::NonZeroUsize; -use std::ops::{Deref, DerefMut}; +use std::{ + convert::AsMut, + fmt::{self, Display}, + num::NonZeroUsize, + ops::{Deref, DerefMut}, +}; use rosidl_runtime_rs::StringExceedsBoundsError; diff --git a/rclrs/src/dynamic_message/field_access/dynamic_message_view.rs b/rclrs/src/dynamic_message/field_access/dynamic_message_view.rs index eb59d1da9..2c1153756 100644 --- a/rclrs/src/dynamic_message/field_access/dynamic_message_view.rs +++ b/rclrs/src/dynamic_message/field_access/dynamic_message_view.rs @@ -1,8 +1,12 @@ -use std::fmt::{self, Debug}; -use std::ops::Deref; - -use super::super::MessageStructure; -use super::{DynamicSequenceElementMut, Proxy, ProxyMut, ProxySequence, Value, ValueMut}; +use std::{ + fmt::{self, Debug}, + ops::Deref, +}; + +use super::{ + super::MessageStructure, DynamicSequenceElementMut, Proxy, ProxyMut, ProxySequence, Value, + ValueMut, +}; /// A view of a single message. Used for nested messages. /// diff --git a/rclrs/src/dynamic_message/field_access/dynamic_sequence.rs b/rclrs/src/dynamic_message/field_access/dynamic_sequence.rs index 3124132a9..271617dea 100644 --- a/rclrs/src/dynamic_message/field_access/dynamic_sequence.rs +++ b/rclrs/src/dynamic_message/field_access/dynamic_sequence.rs @@ -1,6 +1,8 @@ -use std::fmt::{self, Debug}; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; +use std::{ + fmt::{self, Debug}, + marker::PhantomData, + ops::{Deref, DerefMut}, +}; use rosidl_runtime_rs::{Sequence, SequenceAlloc, SequenceExceedsBoundsError}; diff --git a/rclrs/src/dynamic_message/message_structure.rs b/rclrs/src/dynamic_message/message_structure.rs index a28b38ab9..50b007103 100644 --- a/rclrs/src/dynamic_message/message_structure.rs +++ b/rclrs/src/dynamic_message/message_structure.rs @@ -1,10 +1,10 @@ -use std::ffi::CStr; -use std::num::NonZeroUsize; +use std::{ffi::CStr, num::NonZeroUsize}; use super::TypeErasedSequence; -use crate::rcl_bindings::rosidl_typesupport_introspection_c__MessageMember as rosidl_message_member_t; -use crate::rcl_bindings::rosidl_typesupport_introspection_c__MessageMembers as rosidl_message_members_t; -use crate::rcl_bindings::*; +use crate::rcl_bindings::{ + rosidl_typesupport_introspection_c__MessageMember as rosidl_message_member_t, + rosidl_typesupport_introspection_c__MessageMembers as rosidl_message_members_t, *, +}; /// Possible base types for fields in a message. // The field variants are self-explaining, no need to add redundant documentation. @@ -299,7 +299,7 @@ impl MessageStructure { mod tests { use super::*; use crate::dynamic_message::*; - use crate::vendor::test_msgs::msg; + use ros_env::test_msgs::msg; use std::num::NonZeroUsize; diff --git a/rclrs/src/lib.rs b/rclrs/src/lib.rs index 9db4767f9..086f58fd6 100644 --- a/rclrs/src/lib.rs +++ b/rclrs/src/lib.rs @@ -32,7 +32,7 @@ //! //! ```no_run //! use rclrs::*; -//! # use crate::rclrs::vendor::example_interfaces; +//! # use ros_env::example_interfaces; //! //! let context = Context::default_from_env()?; //! let mut executor = context.create_basic_executor(); @@ -59,7 +59,7 @@ //! # let context = Context::default_from_env()?; //! # let mut executor = context.create_basic_executor(); //! # let node = executor.create_node("example_node")?; -//! # use crate::rclrs::vendor::example_interfaces; +//! # use ros_env::example_interfaces; //! # //! // This worker will manage the data for us. //! // The worker's data is called its payload. @@ -99,7 +99,7 @@ //! The following is a simple example of using a mandatory parameter: //! ```no_run //! use rclrs::*; -//! # use crate::rclrs::vendor::example_interfaces; +//! # use ros_env::example_interfaces; //! use std::sync::Arc; //! //! let mut executor = Context::default_from_env()?.create_basic_executor(); @@ -129,7 +129,7 @@ //! //! ```no_run //! use rclrs::*; -//! # use crate::rclrs::vendor::example_interfaces; +//! # use ros_env::example_interfaces; //! use std::time::Duration; //! //! let mut executor = Context::default_from_env()?.create_basic_executor(); @@ -197,7 +197,6 @@ mod subscription; mod time; mod time_source; mod timer; -pub mod vendor; mod wait_set; mod worker; @@ -206,6 +205,13 @@ mod test_helpers; mod rcl_bindings; +#[cfg(feature = "use_ros_shim")] +#[allow(missing_docs)] +pub mod vendor; + +#[cfg(feature = "use_ros_shim")] +pub use vendor::*; + pub use action::*; pub use arguments::*; pub use client::*; diff --git a/rclrs/src/logging.rs b/rclrs/src/logging.rs index 9d669f6d5..d5cd989c5 100644 --- a/rclrs/src/logging.rs +++ b/rclrs/src/logging.rs @@ -670,9 +670,8 @@ mod tests { #[test] fn test_rosout_publishing_default() -> Result<(), RclrsError> { - use crate::{ - rcl_bindings::rcl_logging_rosout_enabled, vendor::rcl_interfaces::msg::rmw::Log, - }; + use crate::rcl_bindings::rcl_logging_rosout_enabled; + use ros_env::rcl_interfaces::msg::rmw::Log; use std::sync::{Arc, Mutex}; let namespace = format!("/test_rosout_publishing_default_{}", line!()); @@ -795,7 +794,7 @@ mod tests { #[test] fn test_rosout_disabled() -> Result<(), RclrsError> { - use crate::vendor::rcl_interfaces::msg::rmw::Log; + use ros_env::rcl_interfaces::msg::rmw::Log; use std::sync::{ atomic::{AtomicBool, Ordering}, Arc, diff --git a/rclrs/src/node.rs b/rclrs/src/node.rs index ed436df25..d7bb375ee 100644 --- a/rclrs/src/node.rs +++ b/rclrs/src/node.rs @@ -274,7 +274,7 @@ impl NodeState { /// In some cases the payload type can be inferred by Rust: /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::example_interfaces; + /// # use ros_env::example_interfaces; /// let executor = Context::default().create_basic_executor(); /// let node = executor.create_node("my_node").unwrap(); /// @@ -300,7 +300,7 @@ impl NodeState { /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::example_interfaces; + /// # use ros_env::example_interfaces; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); /// let worker = node.create_worker::(String::new()); @@ -309,10 +309,9 @@ impl NodeState { /// The data given to the worker can be any custom data type: /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::example_interfaces; + /// # use ros_env::example_interfaces; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); - /// /// #[derive(Default)] /// struct MyNodeData { /// addition_client: Option>, @@ -343,9 +342,9 @@ impl NodeState { /// Pass in only the service name for the `options` argument to use all default client options: /// ``` /// # use rclrs::*; + /// # use ros_env::test_msgs; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); - /// # use crate::rclrs::vendor::test_msgs; /// let client = node.create_client::( /// "my_service" /// ) @@ -357,9 +356,10 @@ impl NodeState { /// /// ``` /// # use rclrs::*; + /// # use ros_env::test_msgs; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); - /// # use crate::rclrs::vendor::test_msgs; + /// /// let client = node.create_client::( /// "my_service" /// .keep_all() @@ -424,9 +424,9 @@ impl NodeState { /// Pass in only the topic name for the `options` argument to use all default publisher options: /// ``` /// # use rclrs::*; + /// # use ros_env::test_msgs; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); - /// # use crate::rclrs::vendor::test_msgs; /// let publisher = node.create_publisher::( /// "my_topic" /// ) @@ -438,7 +438,7 @@ impl NodeState { /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::test_msgs; + /// # use ros_env::test_msgs; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); /// let publisher = node.create_publisher::( @@ -511,7 +511,7 @@ impl NodeState { /// Pass in only the service name for the `options` argument to use all default service options: /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::test_msgs; + /// # use ros_env::test_msgs; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); /// let service = node.create_service::( @@ -528,7 +528,7 @@ impl NodeState { /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::test_msgs; + /// # use ros_env::test_msgs; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); /// let service = node.create_service::( @@ -567,7 +567,7 @@ impl NodeState { /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::example_interfaces; + /// # use ros_env::example_interfaces; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); /// use std::sync::Mutex; @@ -593,7 +593,7 @@ impl NodeState { /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::example_interfaces; + /// # use ros_env::example_interfaces; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); /// use std::sync::{Arc, Mutex}; @@ -687,7 +687,7 @@ impl NodeState { /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::example_interfaces; + /// # use ros_env::example_interfaces; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node")?; /// use std::sync::Arc; @@ -759,7 +759,7 @@ impl NodeState { /// Pass in only the topic name for the `options` argument to use all default subscription options: /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::test_msgs; + /// # use ros_env::test_msgs; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); /// let subscription = node.create_subscription( @@ -775,7 +775,7 @@ impl NodeState { /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::test_msgs; + /// # use ros_env::test_msgs; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); /// let subscription = node.create_subscription( @@ -818,7 +818,7 @@ impl NodeState { /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::example_interfaces; + /// # use ros_env::example_interfaces; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); /// use std::sync::Mutex; @@ -841,7 +841,7 @@ impl NodeState { /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::example_interfaces; + /// # use ros_env::example_interfaces; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); /// use std::sync::{Arc, Mutex}; @@ -1072,7 +1072,7 @@ impl NodeState { /// /// ``` /// # use rclrs::*; - /// # use crate::rclrs::vendor::example_interfaces; + /// # use ros_env::example_interfaces; /// # let executor = Context::default().create_basic_executor(); /// # let node = executor.create_node("my_node").unwrap(); /// @@ -1554,7 +1554,7 @@ mod tests { #[test] fn test_topic_names_and_types() -> Result<(), RclrsError> { - use crate::vendor::test_msgs::msg; + use ros_env::test_msgs::msg; let graph = construct_test_graph("test_topics_graph")?; diff --git a/rclrs/src/parameter.rs b/rclrs/src/parameter.rs index fe9fa0918..b148654cb 100644 --- a/rclrs/src/parameter.rs +++ b/rclrs/src/parameter.rs @@ -8,7 +8,7 @@ pub use range::*; use service::*; pub use value::*; -use crate::vendor::rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}; +use ros_env::rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}; use crate::{ call_string_getter_with_rcl_node, rcl_bindings::*, Node, RclrsError, ENTITY_LIFECYCLE_MUTEX, diff --git a/rclrs/src/parameter/range.rs b/rclrs/src/parameter/range.rs index 6a46d2ff0..fbbe55e9c 100644 --- a/rclrs/src/parameter/range.rs +++ b/rclrs/src/parameter/range.rs @@ -1,7 +1,5 @@ -use crate::{ - vendor::rcl_interfaces::msg::rmw::{FloatingPointRange, IntegerRange}, - DeclarationError, ParameterValue, ParameterVariant, -}; +use crate::{DeclarationError, ParameterValue, ParameterVariant}; +use ros_env::rcl_interfaces::msg::rmw::{FloatingPointRange, IntegerRange}; use rosidl_runtime_rs::{seq, BoundedSequence}; impl From> for ParameterRanges { diff --git a/rclrs/src/parameter/service.rs b/rclrs/src/parameter/service.rs index 5d1c25216..53635d4a8 100644 --- a/rclrs/src/parameter/service.rs +++ b/rclrs/src/parameter/service.rs @@ -3,7 +3,7 @@ use std::{ sync::{Arc, Mutex}, }; -use crate::vendor::rcl_interfaces::{msg::rmw::*, srv::rmw::*}; +use ros_env::rcl_interfaces::{msg::rmw::*, srv::rmw::*}; use rosidl_runtime_rs::Sequence; use super::ParameterMap; @@ -306,14 +306,10 @@ impl ParameterService { #[cfg(test)] mod tests { - use crate::{ - vendor::rcl_interfaces::{ - msg::rmw::{ - Parameter as RmwParameter, ParameterType, ParameterValue as RmwParameterValue, - }, - srv::rmw::*, - }, - *, + use crate::*; + use ros_env::rcl_interfaces::{ + msg::rmw::{Parameter as RmwParameter, ParameterType, ParameterValue as RmwParameterValue}, + srv::rmw::*, }; use rosidl_runtime_rs::{seq, Sequence}; use std::{ diff --git a/rclrs/src/parameter/value.rs b/rclrs/src/parameter/value.rs index 4864ac516..cb232a59d 100644 --- a/rclrs/src/parameter/value.rs +++ b/rclrs/src/parameter/value.rs @@ -3,10 +3,11 @@ use std::{ffi::CStr, sync::Arc}; use crate::{ parameter::{ParameterRange, ParameterRanges}, rcl_bindings::*, - vendor::rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}, ParameterValueError, }; +use ros_env::rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as RmwParameterValue}; + /// A parameter value. /// /// Such a value can be specified in YAML format on the command line, or in a parameter file. diff --git a/rclrs/src/publisher.rs b/rclrs/src/publisher.rs index 6a5717356..1f15faad8 100644 --- a/rclrs/src/publisher.rs +++ b/rclrs/src/publisher.rs @@ -349,14 +349,15 @@ mod tests { #[test] fn traits() { - use crate::vendor::test_msgs; + use ros_env::test_msgs; assert_send::>(); assert_sync::>(); } #[test] fn test_publishers() -> Result<(), RclrsError> { - use crate::{vendor::test_msgs::msg, TopicEndpointInfo}; + use crate::TopicEndpointInfo; + use ros_env::test_msgs::msg; let namespace = "/test_publishers_graph"; let graph = construct_test_graph(namespace)?; diff --git a/rclrs/src/publisher/loaned_message.rs b/rclrs/src/publisher/loaned_message.rs index 4a39d7001..412c8ad1a 100644 --- a/rclrs/src/publisher/loaned_message.rs +++ b/rclrs/src/publisher/loaned_message.rs @@ -98,7 +98,8 @@ mod tests { #[test] fn traits() { - use crate::{test_helpers::*, vendor::test_msgs}; + use crate::test_helpers::*; + use ros_env::test_msgs; assert_send::>(); assert_sync::>(); diff --git a/rclrs/src/service.rs b/rclrs/src/service.rs index 1450c272e..bb9c1c48f 100644 --- a/rclrs/src/service.rs +++ b/rclrs/src/service.rs @@ -398,14 +398,15 @@ mod tests { #[test] fn traits() { - use crate::vendor::test_msgs; + use ros_env::test_msgs; assert_send::>(); assert_sync::>(); } #[test] fn test_services() -> Result<(), RclrsError> { - use crate::{vendor::test_msgs::srv, TopicNamesAndTypes}; + use crate::TopicNamesAndTypes; + use ros_env::test_msgs::srv; let namespace = "/test_services_graph"; let graph = construct_test_graph(namespace)?; diff --git a/rclrs/src/subscription.rs b/rclrs/src/subscription.rs index be195b8f2..16a800a9c 100644 --- a/rclrs/src/subscription.rs +++ b/rclrs/src/subscription.rs @@ -441,7 +441,8 @@ impl Drop for SubscriptionHandle { #[cfg(test)] mod tests { use super::*; - use crate::{test_helpers::*, vendor::test_msgs::msg}; + use crate::test_helpers::*; + use ros_env::test_msgs::msg; #[test] fn traits() { @@ -552,11 +553,12 @@ mod tests { #[test] fn test_delayed_subscription() { - use crate::{vendor::example_interfaces::msg::Empty, *}; + use crate::*; use futures::{ channel::{mpsc, oneshot}, StreamExt, }; + use ros_env::example_interfaces::msg::Empty; use std::sync::atomic::{AtomicBool, Ordering}; let mut executor = Context::default().create_basic_executor(); @@ -620,8 +622,8 @@ mod tests { #[test] fn test_subscription_qos_settings() { - use crate::vendor::example_interfaces::msg::Empty; use crate::*; + use ros_env::example_interfaces::msg::Empty; let executor = Context::default().create_basic_executor(); @@ -672,8 +674,8 @@ mod tests { #[test] fn test_setting_qos_from_parameters() { - use crate::vendor::example_interfaces::msg::Empty; use crate::*; + use ros_env::example_interfaces::msg::Empty; let args = ["--ros-args", "-p", "qos_reliability:=best_effort"].map(ToString::to_string); diff --git a/rclrs/src/subscription/into_async_subscription_callback.rs b/rclrs/src/subscription/into_async_subscription_callback.rs index 334fc0a9a..5ed7da9b6 100644 --- a/rclrs/src/subscription/into_async_subscription_callback.rs +++ b/rclrs/src/subscription/into_async_subscription_callback.rs @@ -103,7 +103,7 @@ where mod tests { use super::*; - type TestMessage = crate::vendor::test_msgs::msg::BoundedSequences; + type TestMessage = ros_env::test_msgs::msg::BoundedSequences; #[test] fn callback_conversion() { diff --git a/rclrs/src/subscription/into_node_subscription_callback.rs b/rclrs/src/subscription/into_node_subscription_callback.rs index 007ee137e..927ff38be 100644 --- a/rclrs/src/subscription/into_node_subscription_callback.rs +++ b/rclrs/src/subscription/into_node_subscription_callback.rs @@ -131,7 +131,7 @@ where mod tests { use super::*; - type TestMessage = crate::vendor::test_msgs::msg::BoundedSequences; + type TestMessage = ros_env::test_msgs::msg::BoundedSequences; #[test] fn callback_conversion() { diff --git a/rclrs/src/subscription/readonly_loaned_message.rs b/rclrs/src/subscription/readonly_loaned_message.rs index db891176e..4a28381d4 100644 --- a/rclrs/src/subscription/readonly_loaned_message.rs +++ b/rclrs/src/subscription/readonly_loaned_message.rs @@ -58,7 +58,8 @@ mod tests { #[test] fn traits() { - use crate::{test_helpers::*, vendor::test_msgs}; + use crate::test_helpers::*; + use ros_env::test_msgs; assert_send::>(); assert_sync::>(); diff --git a/rclrs/src/time.rs b/rclrs/src/time.rs index 1b8250d74..6bd526f85 100644 --- a/rclrs/src/time.rs +++ b/rclrs/src/time.rs @@ -1,4 +1,5 @@ -use crate::{rcl_bindings::*, vendor::builtin_interfaces}; +use crate::rcl_bindings::*; +use ros_env::builtin_interfaces; use std::{ num::TryFromIntError, ops::{Add, Sub}, diff --git a/rclrs/src/time_source.rs b/rclrs/src/time_source.rs index bb2c52fd8..a3c27bb8c 100644 --- a/rclrs/src/time_source.rs +++ b/rclrs/src/time_source.rs @@ -1,9 +1,9 @@ use crate::{ clock::{Clock, ClockSource, ClockType}, - vendor::rosgraph_msgs::msg::Clock as ClockMsg, IntoPrimitiveOptions, Node, NodeState, QoSProfile, ReadOnlyParameter, Subscription, QOS_PROFILE_CLOCK, }; +use ros_env::rosgraph_msgs::msg::Clock as ClockMsg; use std::sync::{Arc, Mutex, RwLock, Weak}; /// Time source for a node that drives the attached clock. diff --git a/rclrs/src/vendor.rs b/rclrs/src/vendor.rs new file mode 100644 index 000000000..f622f6f4b --- /dev/null +++ b/rclrs/src/vendor.rs @@ -0,0 +1,190 @@ +//! Stubs for ROS 2 interfaces to enable documentation builds without any ROS 2 installation sourced. +//! +//! This module provides no useful implementation and should only be used for building documentation. + +macro_rules! impl_message_stub { + ($name:ident) => { + #[derive(Clone, Default, Debug, PartialEq)] + pub struct $name; + + impl rosidl_runtime_rs::Message for $name { + type RmwMsg = rmw::$name; + fn into_rmw_message( + _: std::borrow::Cow<'_, Self>, + ) -> std::borrow::Cow<'_, Self::RmwMsg> { + todo!() + } + fn from_rmw_message(_: Self::RmwMsg) -> Self { + todo!() + } + } + }; +} + +macro_rules! impl_rmw_message_stub { + ($name:ident) => { + #[derive(Clone, Default, Debug, PartialEq)] + pub struct $name; + + impl rosidl_runtime_rs::Message for $name { + type RmwMsg = Self; + fn into_rmw_message( + _: std::borrow::Cow<'_, Self>, + ) -> std::borrow::Cow<'_, Self::RmwMsg> { + todo!() + } + fn from_rmw_message(_: Self::RmwMsg) -> Self { + todo!() + } + } + + impl rosidl_runtime_rs::RmwMessage for $name + where + Self: Sized, + { + const TYPE_NAME: &'static str = ""; + fn get_type_support() -> *const std::ffi::c_void { + todo!() + } + } + }; +} + +macro_rules! impl_service_stub { + ($name:ident) => { + pub struct $name; + + impl rosidl_runtime_rs::Service for $name { + paste::paste! { + type Request = [<$name _Request>]; + type Response = [<$name _Response>]; + } + + fn get_type_support() -> *const std::ffi::c_void { + todo!() + } + } + + paste::paste! { + impl_rmw_message_stub!([<$name _Request>]); + impl_rmw_message_stub!([<$name _Response>]); + } + }; +} + +macro_rules! impl_sequence_alloc_stub { + ($name:ident) => { + impl rosidl_runtime_rs::SequenceAlloc for $name { + fn sequence_init(_: &mut rosidl_runtime_rs::Sequence, _: usize) -> bool { + todo!() + } + fn sequence_fini(_: &mut rosidl_runtime_rs::Sequence) { + todo!() + } + fn sequence_copy( + _: &rosidl_runtime_rs::Sequence, + _: &mut rosidl_runtime_rs::Sequence, + ) -> bool { + todo!() + } + } + }; +} + +#[allow(non_camel_case_types)] +/// Stub module for the [action_msgs](https://github.com/ros2/rcl_interfaces/tree/rolling/action_msgs) ROS 2 package. +/// +/// Not all messages and services are implemented, only the ones used internally by [rclrs](crate). +pub mod action_msgs { + pub mod msg { + impl_message_stub!(GoalInfo); + + pub mod rmw { + impl_rmw_message_stub!(GoalInfo); + } + } + pub mod srv { + impl_message_stub!(CancelGoal_Response); + impl_message_stub!(CancelGoal_Request); + + pub mod rmw { + impl_rmw_message_stub!(CancelGoal_Response); + impl_rmw_message_stub!(CancelGoal_Request); + } + } +} + +/// Stub module for the [builtin_interfaces](https://github.com/ros2/rcl_interfaces/tree/rolling/builtin_interfaces) ROS 2 package. +/// +/// Not all messages are implemented, only the ones used internally by [rclrs](crate). +pub mod builtin_interfaces { + pub mod msg { + impl_message_stub!(Time); + + pub mod rmw { + impl_rmw_message_stub!(Time); + } + } +} + +/// Stub module for the [unique_identifier_msgs](https://github.com/ros2/unique_identifier_msgs/tree/rolling) ROS 2 package. +/// +/// Not all messages are implemented, only the ones used internally by [rclrs](crate). +pub mod unique_identifier_msgs { + pub mod msg { + impl_message_stub!(UUID); + + pub mod rmw { + impl_rmw_message_stub!(UUID); + } + } +} + +/// Stub module for the [rosgraph_msgs](https://github.com/ros2/rcl_interfaces/tree/rolling/rosgraph_msgs) ROS 2 package. +/// +/// Not all messages are implemented, only the ones used internally by [rclrs](crate). +pub mod rosgraph_msgs { + pub mod msg { + impl_message_stub!(Clock); + + pub mod rmw { + impl_rmw_message_stub!(Clock); + } + } +} + +#[allow(non_camel_case_types)] +/// Stub module for the [rcl_interfaces](https://github.com/ros2/rcl_interfaces/tree/rolling/rcl_interfaces) ROS 2 package. +/// +/// Not all messages and services are implemented, only the ones used internally by [rclrs](crate). +pub mod rcl_interfaces { + pub mod msg { + impl_message_stub!(ParameterType); + impl_message_stub!(ParameterValue); + + impl_message_stub!(FloatingPointRange); + impl_message_stub!(IntegerRange); + + pub mod rmw { + impl_rmw_message_stub!(ParameterType); + impl_rmw_message_stub!(ParameterValue); + + impl_rmw_message_stub!(FloatingPointRange); + impl_sequence_alloc_stub!(FloatingPointRange); + + impl_rmw_message_stub!(IntegerRange); + impl_sequence_alloc_stub!(IntegerRange); + } + } + + pub mod srv { + pub mod rmw { + impl_service_stub!(DescribeParameters); + impl_service_stub!(GetParameters); + impl_service_stub!(GetParameterTypes); + impl_service_stub!(ListParameters); + impl_service_stub!(SetParameters); + impl_service_stub!(SetParametersAtomically); + } + } +} diff --git a/rclrs/src/vendor/action_msgs/mod.rs b/rclrs/src/vendor/action_msgs/mod.rs deleted file mode 100644 index f43deda46..000000000 --- a/rclrs/src/vendor/action_msgs/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![allow(non_camel_case_types)] -#![allow(clippy::derive_partial_eq_without_eq)] -#![allow(clippy::upper_case_acronyms)] - -pub mod msg; - -pub mod srv; diff --git a/rclrs/src/vendor/action_msgs/msg.rs b/rclrs/src/vendor/action_msgs/msg.rs deleted file mode 100644 index cb195e4c0..000000000 --- a/rclrs/src/vendor/action_msgs/msg.rs +++ /dev/null @@ -1,457 +0,0 @@ -pub mod rmw { - #[cfg(feature = "serde")] - use serde::{Deserialize, Serialize}; - - #[link(name = "action_msgs__rosidl_typesupport_c")] - unsafe extern "C" { - fn rosidl_typesupport_c__get_message_type_support_handle__action_msgs__msg__GoalInfo( - ) -> *const std::ffi::c_void; - } - - #[link(name = "action_msgs__rosidl_generator_c")] - unsafe extern "C" { - fn action_msgs__msg__GoalInfo__init(msg: *mut GoalInfo) -> bool; - fn action_msgs__msg__GoalInfo__Sequence__init( - seq: *mut rosidl_runtime_rs::Sequence, - size: usize, - ) -> bool; - fn action_msgs__msg__GoalInfo__Sequence__fini( - seq: *mut rosidl_runtime_rs::Sequence, - ); - fn action_msgs__msg__GoalInfo__Sequence__copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: *mut rosidl_runtime_rs::Sequence, - ) -> bool; - } - - // Corresponds to action_msgs__msg__GoalInfo - #[repr(C)] - #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] - #[derive(Clone, Debug, PartialEq, PartialOrd)] - pub struct GoalInfo { - pub goal_id: crate::vendor::unique_identifier_msgs::msg::rmw::UUID, - pub stamp: crate::vendor::builtin_interfaces::msg::rmw::Time, - } - - impl Default for GoalInfo { - fn default() -> Self { - unsafe { - let mut msg = std::mem::zeroed(); - if !action_msgs__msg__GoalInfo__init(&mut msg as *mut _) { - panic!("Call to action_msgs__msg__GoalInfo__init() failed"); - } - msg - } - } - } - - impl rosidl_runtime_rs::SequenceAlloc for GoalInfo { - fn sequence_init(seq: &mut rosidl_runtime_rs::Sequence, size: usize) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__msg__GoalInfo__Sequence__init(seq as *mut _, size) } - } - fn sequence_fini(seq: &mut rosidl_runtime_rs::Sequence) { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__msg__GoalInfo__Sequence__fini(seq as *mut _) } - } - fn sequence_copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: &mut rosidl_runtime_rs::Sequence, - ) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__msg__GoalInfo__Sequence__copy(in_seq, out_seq as *mut _) } - } - } - - impl rosidl_runtime_rs::Message for GoalInfo { - type RmwMsg = Self; - fn into_rmw_message( - msg_cow: std::borrow::Cow<'_, Self>, - ) -> std::borrow::Cow<'_, Self::RmwMsg> { - msg_cow - } - fn from_rmw_message(msg: Self::RmwMsg) -> Self { - msg - } - } - - impl rosidl_runtime_rs::RmwMessage for GoalInfo - where - Self: Sized, - { - const TYPE_NAME: &'static str = "action_msgs/msg/GoalInfo"; - fn get_type_support() -> *const std::ffi::c_void { - // SAFETY: No preconditions for this function. - unsafe { - rosidl_typesupport_c__get_message_type_support_handle__action_msgs__msg__GoalInfo() - } - } - } - - #[link(name = "action_msgs__rosidl_typesupport_c")] - unsafe extern "C" { - fn rosidl_typesupport_c__get_message_type_support_handle__action_msgs__msg__GoalStatus( - ) -> *const std::ffi::c_void; - } - - #[link(name = "action_msgs__rosidl_generator_c")] - unsafe extern "C" { - fn action_msgs__msg__GoalStatus__init(msg: *mut GoalStatus) -> bool; - fn action_msgs__msg__GoalStatus__Sequence__init( - seq: *mut rosidl_runtime_rs::Sequence, - size: usize, - ) -> bool; - fn action_msgs__msg__GoalStatus__Sequence__fini( - seq: *mut rosidl_runtime_rs::Sequence, - ); - fn action_msgs__msg__GoalStatus__Sequence__copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: *mut rosidl_runtime_rs::Sequence, - ) -> bool; - } - - // Corresponds to action_msgs__msg__GoalStatus - #[repr(C)] - #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] - #[derive(Clone, Debug, PartialEq, PartialOrd)] - pub struct GoalStatus { - pub goal_info: crate::vendor::action_msgs::msg::rmw::GoalInfo, - pub status: i8, - } - - impl GoalStatus { - /// Indicates status has not been properly set. - pub const STATUS_UNKNOWN: i8 = 0; - /// The goal has been accepted and is awaiting execution. - pub const STATUS_ACCEPTED: i8 = 1; - /// The goal is currently being executed by the action server. - pub const STATUS_EXECUTING: i8 = 2; - /// The client has requested that the goal be canceled and the action server has - /// accepted the cancel request. - pub const STATUS_CANCELING: i8 = 3; - /// The goal was achieved successfully by the action server. - pub const STATUS_SUCCEEDED: i8 = 4; - /// The goal was canceled after an external request from an action client. - pub const STATUS_CANCELED: i8 = 5; - /// The goal was terminated by the action server without an external request. - pub const STATUS_ABORTED: i8 = 6; - } - - impl Default for GoalStatus { - fn default() -> Self { - unsafe { - let mut msg = std::mem::zeroed(); - if !action_msgs__msg__GoalStatus__init(&mut msg as *mut _) { - panic!("Call to action_msgs__msg__GoalStatus__init() failed"); - } - msg - } - } - } - - impl rosidl_runtime_rs::SequenceAlloc for GoalStatus { - fn sequence_init(seq: &mut rosidl_runtime_rs::Sequence, size: usize) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__msg__GoalStatus__Sequence__init(seq as *mut _, size) } - } - fn sequence_fini(seq: &mut rosidl_runtime_rs::Sequence) { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__msg__GoalStatus__Sequence__fini(seq as *mut _) } - } - fn sequence_copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: &mut rosidl_runtime_rs::Sequence, - ) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__msg__GoalStatus__Sequence__copy(in_seq, out_seq as *mut _) } - } - } - - impl rosidl_runtime_rs::Message for GoalStatus { - type RmwMsg = Self; - fn into_rmw_message( - msg_cow: std::borrow::Cow<'_, Self>, - ) -> std::borrow::Cow<'_, Self::RmwMsg> { - msg_cow - } - fn from_rmw_message(msg: Self::RmwMsg) -> Self { - msg - } - } - - impl rosidl_runtime_rs::RmwMessage for GoalStatus - where - Self: Sized, - { - const TYPE_NAME: &'static str = "action_msgs/msg/GoalStatus"; - fn get_type_support() -> *const std::ffi::c_void { - // SAFETY: No preconditions for this function. - unsafe { - rosidl_typesupport_c__get_message_type_support_handle__action_msgs__msg__GoalStatus( - ) - } - } - } - - #[link(name = "action_msgs__rosidl_typesupport_c")] - unsafe extern "C" { - fn rosidl_typesupport_c__get_message_type_support_handle__action_msgs__msg__GoalStatusArray( - ) -> *const std::ffi::c_void; - } - - #[link(name = "action_msgs__rosidl_generator_c")] - unsafe extern "C" { - fn action_msgs__msg__GoalStatusArray__init(msg: *mut GoalStatusArray) -> bool; - fn action_msgs__msg__GoalStatusArray__Sequence__init( - seq: *mut rosidl_runtime_rs::Sequence, - size: usize, - ) -> bool; - fn action_msgs__msg__GoalStatusArray__Sequence__fini( - seq: *mut rosidl_runtime_rs::Sequence, - ); - fn action_msgs__msg__GoalStatusArray__Sequence__copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: *mut rosidl_runtime_rs::Sequence, - ) -> bool; - } - - // Corresponds to action_msgs__msg__GoalStatusArray - #[repr(C)] - #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] - #[derive(Clone, Debug, PartialEq, PartialOrd)] - pub struct GoalStatusArray { - pub status_list: - rosidl_runtime_rs::Sequence, - } - - impl Default for GoalStatusArray { - fn default() -> Self { - unsafe { - let mut msg = std::mem::zeroed(); - if !action_msgs__msg__GoalStatusArray__init(&mut msg as *mut _) { - panic!("Call to action_msgs__msg__GoalStatusArray__init() failed"); - } - msg - } - } - } - - impl rosidl_runtime_rs::SequenceAlloc for GoalStatusArray { - fn sequence_init(seq: &mut rosidl_runtime_rs::Sequence, size: usize) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__msg__GoalStatusArray__Sequence__init(seq as *mut _, size) } - } - fn sequence_fini(seq: &mut rosidl_runtime_rs::Sequence) { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__msg__GoalStatusArray__Sequence__fini(seq as *mut _) } - } - fn sequence_copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: &mut rosidl_runtime_rs::Sequence, - ) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__msg__GoalStatusArray__Sequence__copy(in_seq, out_seq as *mut _) } - } - } - - impl rosidl_runtime_rs::Message for GoalStatusArray { - type RmwMsg = Self; - fn into_rmw_message( - msg_cow: std::borrow::Cow<'_, Self>, - ) -> std::borrow::Cow<'_, Self::RmwMsg> { - msg_cow - } - fn from_rmw_message(msg: Self::RmwMsg) -> Self { - msg - } - } - - impl rosidl_runtime_rs::RmwMessage for GoalStatusArray - where - Self: Sized, - { - const TYPE_NAME: &'static str = "action_msgs/msg/GoalStatusArray"; - fn get_type_support() -> *const std::ffi::c_void { - // SAFETY: No preconditions for this function. - unsafe { - rosidl_typesupport_c__get_message_type_support_handle__action_msgs__msg__GoalStatusArray() - } - } - } -} // mod rmw - -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[derive(Clone, Debug, PartialEq, PartialOrd)] -pub struct GoalInfo { - pub goal_id: crate::vendor::unique_identifier_msgs::msg::UUID, - pub stamp: crate::vendor::builtin_interfaces::msg::Time, -} - -impl Default for GoalInfo { - fn default() -> Self { - ::from_rmw_message( - crate::vendor::action_msgs::msg::rmw::GoalInfo::default(), - ) - } -} - -impl rosidl_runtime_rs::Message for GoalInfo { - type RmwMsg = crate::vendor::action_msgs::msg::rmw::GoalInfo; - - fn into_rmw_message(msg_cow: std::borrow::Cow<'_, Self>) -> std::borrow::Cow<'_, Self::RmwMsg> { - match msg_cow { - std::borrow::Cow::Owned(msg) => std::borrow::Cow::Owned(Self::RmwMsg { - goal_id: crate::vendor::unique_identifier_msgs::msg::UUID::into_rmw_message( - std::borrow::Cow::Owned(msg.goal_id), - ) - .into_owned(), - stamp: crate::vendor::builtin_interfaces::msg::Time::into_rmw_message( - std::borrow::Cow::Owned(msg.stamp), - ) - .into_owned(), - }), - std::borrow::Cow::Borrowed(msg) => std::borrow::Cow::Owned(Self::RmwMsg { - goal_id: crate::vendor::unique_identifier_msgs::msg::UUID::into_rmw_message( - std::borrow::Cow::Borrowed(&msg.goal_id), - ) - .into_owned(), - stamp: crate::vendor::builtin_interfaces::msg::Time::into_rmw_message( - std::borrow::Cow::Borrowed(&msg.stamp), - ) - .into_owned(), - }), - } - } - - fn from_rmw_message(msg: Self::RmwMsg) -> Self { - Self { - goal_id: crate::vendor::unique_identifier_msgs::msg::UUID::from_rmw_message( - msg.goal_id, - ), - stamp: crate::vendor::builtin_interfaces::msg::Time::from_rmw_message(msg.stamp), - } - } -} - -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[derive(Clone, Debug, PartialEq, PartialOrd)] -pub struct GoalStatus { - pub goal_info: crate::vendor::action_msgs::msg::GoalInfo, - pub status: i8, -} - -impl GoalStatus { - /// Indicates status has not been properly set. - pub const STATUS_UNKNOWN: i8 = 0; - /// The goal has been accepted and is awaiting execution. - pub const STATUS_ACCEPTED: i8 = 1; - /// The goal is currently being executed by the action server. - pub const STATUS_EXECUTING: i8 = 2; - /// The client has requested that the goal be canceled and the action server has - /// accepted the cancel request. - pub const STATUS_CANCELING: i8 = 3; - /// The goal was achieved successfully by the action server. - pub const STATUS_SUCCEEDED: i8 = 4; - /// The goal was canceled after an external request from an action client. - pub const STATUS_CANCELED: i8 = 5; - /// The goal was terminated by the action server without an external request. - pub const STATUS_ABORTED: i8 = 6; -} - -impl Default for GoalStatus { - fn default() -> Self { - ::from_rmw_message( - crate::vendor::action_msgs::msg::rmw::GoalStatus::default(), - ) - } -} - -impl rosidl_runtime_rs::Message for GoalStatus { - type RmwMsg = crate::vendor::action_msgs::msg::rmw::GoalStatus; - - fn into_rmw_message(msg_cow: std::borrow::Cow<'_, Self>) -> std::borrow::Cow<'_, Self::RmwMsg> { - match msg_cow { - std::borrow::Cow::Owned(msg) => std::borrow::Cow::Owned(Self::RmwMsg { - goal_info: crate::vendor::action_msgs::msg::GoalInfo::into_rmw_message( - std::borrow::Cow::Owned(msg.goal_info), - ) - .into_owned(), - status: msg.status, - }), - std::borrow::Cow::Borrowed(msg) => std::borrow::Cow::Owned(Self::RmwMsg { - goal_info: crate::vendor::action_msgs::msg::GoalInfo::into_rmw_message( - std::borrow::Cow::Borrowed(&msg.goal_info), - ) - .into_owned(), - status: msg.status, - }), - } - } - - fn from_rmw_message(msg: Self::RmwMsg) -> Self { - Self { - goal_info: crate::vendor::action_msgs::msg::GoalInfo::from_rmw_message(msg.goal_info), - status: msg.status, - } - } -} - -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[derive(Clone, Debug, PartialEq, PartialOrd)] -pub struct GoalStatusArray { - pub status_list: Vec, -} - -impl Default for GoalStatusArray { - fn default() -> Self { - ::from_rmw_message( - crate::vendor::action_msgs::msg::rmw::GoalStatusArray::default(), - ) - } -} - -impl rosidl_runtime_rs::Message for GoalStatusArray { - type RmwMsg = crate::vendor::action_msgs::msg::rmw::GoalStatusArray; - - fn into_rmw_message(msg_cow: std::borrow::Cow<'_, Self>) -> std::borrow::Cow<'_, Self::RmwMsg> { - match msg_cow { - std::borrow::Cow::Owned(msg) => std::borrow::Cow::Owned(Self::RmwMsg { - status_list: msg - .status_list - .into_iter() - .map(|elem| { - crate::vendor::action_msgs::msg::GoalStatus::into_rmw_message( - std::borrow::Cow::Owned(elem), - ) - .into_owned() - }) - .collect(), - }), - std::borrow::Cow::Borrowed(msg) => std::borrow::Cow::Owned(Self::RmwMsg { - status_list: msg - .status_list - .iter() - .map(|elem| { - crate::vendor::action_msgs::msg::GoalStatus::into_rmw_message( - std::borrow::Cow::Borrowed(elem), - ) - .into_owned() - }) - .collect(), - }), - } - } - - fn from_rmw_message(msg: Self::RmwMsg) -> Self { - Self { - status_list: msg - .status_list - .into_iter() - .map(crate::vendor::action_msgs::msg::GoalStatus::from_rmw_message) - .collect(), - } - } -} diff --git a/rclrs/src/vendor/action_msgs/srv.rs b/rclrs/src/vendor/action_msgs/srv.rs deleted file mode 100644 index 90c29b279..000000000 --- a/rclrs/src/vendor/action_msgs/srv.rs +++ /dev/null @@ -1,375 +0,0 @@ -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[derive(Clone, Debug, PartialEq, PartialOrd)] -pub struct CancelGoal_Request { - pub goal_info: crate::vendor::action_msgs::msg::GoalInfo, -} - -impl Default for CancelGoal_Request { - fn default() -> Self { - ::from_rmw_message( - crate::vendor::action_msgs::srv::rmw::CancelGoal_Request::default(), - ) - } -} - -impl rosidl_runtime_rs::Message for CancelGoal_Request { - type RmwMsg = crate::vendor::action_msgs::srv::rmw::CancelGoal_Request; - - fn into_rmw_message(msg_cow: std::borrow::Cow<'_, Self>) -> std::borrow::Cow<'_, Self::RmwMsg> { - match msg_cow { - std::borrow::Cow::Owned(msg) => std::borrow::Cow::Owned(Self::RmwMsg { - goal_info: crate::vendor::action_msgs::msg::GoalInfo::into_rmw_message( - std::borrow::Cow::Owned(msg.goal_info), - ) - .into_owned(), - }), - std::borrow::Cow::Borrowed(msg) => std::borrow::Cow::Owned(Self::RmwMsg { - goal_info: crate::vendor::action_msgs::msg::GoalInfo::into_rmw_message( - std::borrow::Cow::Borrowed(&msg.goal_info), - ) - .into_owned(), - }), - } - } - - fn from_rmw_message(msg: Self::RmwMsg) -> Self { - Self { - goal_info: crate::vendor::action_msgs::msg::GoalInfo::from_rmw_message(msg.goal_info), - } - } -} - -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[derive(Clone, Debug, PartialEq, PartialOrd)] -pub struct CancelGoal_Response { - pub return_code: i8, - pub goals_canceling: Vec, -} - -impl CancelGoal_Response { - /// Indicates the request was accepted without any errors. - /// - /// One or more goals have transitioned to the CANCELING state. The - /// goals_canceling list is not empty. - pub const ERROR_NONE: i8 = 0; - /// Indicates the request was rejected. - /// - /// No goals have transitioned to the CANCELING state. The goals_canceling list is - /// empty. - pub const ERROR_REJECTED: i8 = 1; - /// Indicates the requested goal ID does not exist. - /// - /// No goals have transitioned to the CANCELING state. The goals_canceling list is - /// empty. - pub const ERROR_UNKNOWN_GOAL_ID: i8 = 2; - /// Indicates the goal is not cancelable because it is already in a terminal state. - /// - /// No goals have transitioned to the CANCELING state. The goals_canceling list is - /// empty. - pub const ERROR_GOAL_TERMINATED: i8 = 3; -} - -impl Default for CancelGoal_Response { - fn default() -> Self { - ::from_rmw_message( - crate::vendor::action_msgs::srv::rmw::CancelGoal_Response::default(), - ) - } -} - -impl rosidl_runtime_rs::Message for CancelGoal_Response { - type RmwMsg = crate::vendor::action_msgs::srv::rmw::CancelGoal_Response; - - fn into_rmw_message(msg_cow: std::borrow::Cow<'_, Self>) -> std::borrow::Cow<'_, Self::RmwMsg> { - match msg_cow { - std::borrow::Cow::Owned(msg) => std::borrow::Cow::Owned(Self::RmwMsg { - return_code: msg.return_code, - goals_canceling: msg - .goals_canceling - .into_iter() - .map(|elem| { - crate::vendor::action_msgs::msg::GoalInfo::into_rmw_message( - std::borrow::Cow::Owned(elem), - ) - .into_owned() - }) - .collect(), - }), - std::borrow::Cow::Borrowed(msg) => std::borrow::Cow::Owned(Self::RmwMsg { - return_code: msg.return_code, - goals_canceling: msg - .goals_canceling - .iter() - .map(|elem| { - crate::vendor::action_msgs::msg::GoalInfo::into_rmw_message( - std::borrow::Cow::Borrowed(elem), - ) - .into_owned() - }) - .collect(), - }), - } - } - - fn from_rmw_message(msg: Self::RmwMsg) -> Self { - Self { - return_code: msg.return_code, - goals_canceling: msg - .goals_canceling - .into_iter() - .map(crate::vendor::action_msgs::msg::GoalInfo::from_rmw_message) - .collect(), - } - } -} - -#[link(name = "action_msgs__rosidl_typesupport_c")] -unsafe extern "C" { - fn rosidl_typesupport_c__get_service_type_support_handle__action_msgs__srv__CancelGoal( - ) -> *const std::ffi::c_void; -} - -// Corresponds to action_msgs__srv__CancelGoal -pub struct CancelGoal; - -impl rosidl_runtime_rs::Service for CancelGoal { - type Request = crate::vendor::action_msgs::srv::CancelGoal_Request; - type Response = crate::vendor::action_msgs::srv::CancelGoal_Response; - - fn get_type_support() -> *const std::ffi::c_void { - // SAFETY: No preconditions for this function. - unsafe { - rosidl_typesupport_c__get_service_type_support_handle__action_msgs__srv__CancelGoal() - } - } -} - -pub mod rmw { - - #[cfg(feature = "serde")] - use serde::{Deserialize, Serialize}; - - #[link(name = "action_msgs__rosidl_typesupport_c")] - unsafe extern "C" { - fn rosidl_typesupport_c__get_message_type_support_handle__action_msgs__srv__CancelGoal_Request( - ) -> *const std::ffi::c_void; - } - - #[link(name = "action_msgs__rosidl_generator_c")] - unsafe extern "C" { - fn action_msgs__srv__CancelGoal_Request__init(msg: *mut CancelGoal_Request) -> bool; - fn action_msgs__srv__CancelGoal_Request__Sequence__init( - seq: *mut rosidl_runtime_rs::Sequence, - size: usize, - ) -> bool; - fn action_msgs__srv__CancelGoal_Request__Sequence__fini( - seq: *mut rosidl_runtime_rs::Sequence, - ); - fn action_msgs__srv__CancelGoal_Request__Sequence__copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: *mut rosidl_runtime_rs::Sequence, - ) -> bool; - } - - // Corresponds to action_msgs__srv__CancelGoal_Request - #[repr(C)] - #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] - #[derive(Clone, Debug, PartialEq, PartialOrd)] - pub struct CancelGoal_Request { - pub goal_info: crate::vendor::action_msgs::msg::rmw::GoalInfo, - } - - impl Default for CancelGoal_Request { - fn default() -> Self { - unsafe { - let mut msg = std::mem::zeroed(); - if !action_msgs__srv__CancelGoal_Request__init(&mut msg as *mut _) { - panic!("Call to action_msgs__srv__CancelGoal_Request__init() failed"); - } - msg - } - } - } - - impl rosidl_runtime_rs::SequenceAlloc for CancelGoal_Request { - fn sequence_init(seq: &mut rosidl_runtime_rs::Sequence, size: usize) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__srv__CancelGoal_Request__Sequence__init(seq as *mut _, size) } - } - fn sequence_fini(seq: &mut rosidl_runtime_rs::Sequence) { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__srv__CancelGoal_Request__Sequence__fini(seq as *mut _) } - } - fn sequence_copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: &mut rosidl_runtime_rs::Sequence, - ) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { - action_msgs__srv__CancelGoal_Request__Sequence__copy(in_seq, out_seq as *mut _) - } - } - } - - impl rosidl_runtime_rs::Message for CancelGoal_Request { - type RmwMsg = Self; - fn into_rmw_message( - msg_cow: std::borrow::Cow<'_, Self>, - ) -> std::borrow::Cow<'_, Self::RmwMsg> { - msg_cow - } - fn from_rmw_message(msg: Self::RmwMsg) -> Self { - msg - } - } - - impl rosidl_runtime_rs::RmwMessage for CancelGoal_Request - where - Self: Sized, - { - const TYPE_NAME: &'static str = "action_msgs/srv/CancelGoal_Request"; - fn get_type_support() -> *const std::ffi::c_void { - // SAFETY: No preconditions for this function. - unsafe { - rosidl_typesupport_c__get_message_type_support_handle__action_msgs__srv__CancelGoal_Request() - } - } - } - - #[link(name = "action_msgs__rosidl_typesupport_c")] - unsafe extern "C" { - fn rosidl_typesupport_c__get_message_type_support_handle__action_msgs__srv__CancelGoal_Response( - ) -> *const std::ffi::c_void; - } - - #[link(name = "action_msgs__rosidl_generator_c")] - unsafe extern "C" { - fn action_msgs__srv__CancelGoal_Response__init(msg: *mut CancelGoal_Response) -> bool; - fn action_msgs__srv__CancelGoal_Response__Sequence__init( - seq: *mut rosidl_runtime_rs::Sequence, - size: usize, - ) -> bool; - fn action_msgs__srv__CancelGoal_Response__Sequence__fini( - seq: *mut rosidl_runtime_rs::Sequence, - ); - fn action_msgs__srv__CancelGoal_Response__Sequence__copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: *mut rosidl_runtime_rs::Sequence, - ) -> bool; - } - - // Corresponds to action_msgs__srv__CancelGoal_Response - #[repr(C)] - #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] - #[derive(Clone, Debug, PartialEq, PartialOrd)] - pub struct CancelGoal_Response { - pub return_code: i8, - pub goals_canceling: - rosidl_runtime_rs::Sequence, - } - - impl CancelGoal_Response { - /// Indicates the request was accepted without any errors. - /// - /// One or more goals have transitioned to the CANCELING state. The - /// goals_canceling list is not empty. - pub const ERROR_NONE: i8 = 0; - /// Indicates the request was rejected. - /// - /// No goals have transitioned to the CANCELING state. The goals_canceling list is - /// empty. - pub const ERROR_REJECTED: i8 = 1; - /// Indicates the requested goal ID does not exist. - /// - /// No goals have transitioned to the CANCELING state. The goals_canceling list is - /// empty. - pub const ERROR_UNKNOWN_GOAL_ID: i8 = 2; - /// Indicates the goal is not cancelable because it is already in a terminal state. - /// - /// No goals have transitioned to the CANCELING state. The goals_canceling list is - /// empty. - pub const ERROR_GOAL_TERMINATED: i8 = 3; - } - - impl Default for CancelGoal_Response { - fn default() -> Self { - unsafe { - let mut msg = std::mem::zeroed(); - if !action_msgs__srv__CancelGoal_Response__init(&mut msg as *mut _) { - panic!("Call to action_msgs__srv__CancelGoal_Response__init() failed"); - } - msg - } - } - } - - impl rosidl_runtime_rs::SequenceAlloc for CancelGoal_Response { - fn sequence_init(seq: &mut rosidl_runtime_rs::Sequence, size: usize) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__srv__CancelGoal_Response__Sequence__init(seq as *mut _, size) } - } - fn sequence_fini(seq: &mut rosidl_runtime_rs::Sequence) { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { action_msgs__srv__CancelGoal_Response__Sequence__fini(seq as *mut _) } - } - fn sequence_copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: &mut rosidl_runtime_rs::Sequence, - ) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { - action_msgs__srv__CancelGoal_Response__Sequence__copy(in_seq, out_seq as *mut _) - } - } - } - - impl rosidl_runtime_rs::Message for CancelGoal_Response { - type RmwMsg = Self; - fn into_rmw_message( - msg_cow: std::borrow::Cow<'_, Self>, - ) -> std::borrow::Cow<'_, Self::RmwMsg> { - msg_cow - } - fn from_rmw_message(msg: Self::RmwMsg) -> Self { - msg - } - } - - impl rosidl_runtime_rs::RmwMessage for CancelGoal_Response - where - Self: Sized, - { - const TYPE_NAME: &'static str = "action_msgs/srv/CancelGoal_Response"; - fn get_type_support() -> *const std::ffi::c_void { - // SAFETY: No preconditions for this function. - unsafe { - rosidl_typesupport_c__get_message_type_support_handle__action_msgs__srv__CancelGoal_Response() - } - } - } - - #[link(name = "action_msgs__rosidl_typesupport_c")] - unsafe extern "C" { - fn rosidl_typesupport_c__get_service_type_support_handle__action_msgs__srv__CancelGoal( - ) -> *const std::ffi::c_void; - } - - // Corresponds to action_msgs__srv__CancelGoal - pub struct CancelGoal; - - impl rosidl_runtime_rs::Service for CancelGoal { - type Request = crate::vendor::action_msgs::srv::rmw::CancelGoal_Request; - type Response = crate::vendor::action_msgs::srv::rmw::CancelGoal_Response; - - fn get_type_support() -> *const std::ffi::c_void { - // SAFETY: No preconditions for this function. - unsafe { - rosidl_typesupport_c__get_service_type_support_handle__action_msgs__srv__CancelGoal( - ) - } - } - } -} // mod rmw diff --git a/rclrs/src/vendor/builtin_interfaces/mod.rs b/rclrs/src/vendor/builtin_interfaces/mod.rs deleted file mode 100644 index 4c61d56a1..000000000 --- a/rclrs/src/vendor/builtin_interfaces/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![allow(non_camel_case_types)] -#![allow(clippy::derive_partial_eq_without_eq)] -#![allow(clippy::upper_case_acronyms)] - -pub mod msg; diff --git a/rclrs/src/vendor/builtin_interfaces/msg.rs b/rclrs/src/vendor/builtin_interfaces/msg.rs deleted file mode 100644 index 96364544a..000000000 --- a/rclrs/src/vendor/builtin_interfaces/msg.rs +++ /dev/null @@ -1,258 +0,0 @@ -pub mod rmw { - #[cfg(feature = "serde")] - use serde::{Deserialize, Serialize}; - - #[link(name = "builtin_interfaces__rosidl_typesupport_c")] - unsafe extern "C" { - fn rosidl_typesupport_c__get_message_type_support_handle__builtin_interfaces__msg__Duration( - ) -> *const std::ffi::c_void; - } - - #[link(name = "builtin_interfaces__rosidl_generator_c")] - unsafe extern "C" { - fn builtin_interfaces__msg__Duration__init(msg: *mut Duration) -> bool; - fn builtin_interfaces__msg__Duration__Sequence__init( - seq: *mut rosidl_runtime_rs::Sequence, - size: usize, - ) -> bool; - fn builtin_interfaces__msg__Duration__Sequence__fini( - seq: *mut rosidl_runtime_rs::Sequence, - ); - fn builtin_interfaces__msg__Duration__Sequence__copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: *mut rosidl_runtime_rs::Sequence, - ) -> bool; - } - - // Corresponds to builtin_interfaces__msg__Duration - #[repr(C)] - #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] - #[derive(Clone, Debug, PartialEq, PartialOrd)] - pub struct Duration { - pub sec: i32, - pub nanosec: u32, - } - - impl Default for Duration { - fn default() -> Self { - unsafe { - let mut msg = std::mem::zeroed(); - if !builtin_interfaces__msg__Duration__init(&mut msg as *mut _) { - panic!("Call to builtin_interfaces__msg__Duration__init() failed"); - } - msg - } - } - } - - impl rosidl_runtime_rs::SequenceAlloc for Duration { - fn sequence_init(seq: &mut rosidl_runtime_rs::Sequence, size: usize) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { builtin_interfaces__msg__Duration__Sequence__init(seq as *mut _, size) } - } - fn sequence_fini(seq: &mut rosidl_runtime_rs::Sequence) { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { builtin_interfaces__msg__Duration__Sequence__fini(seq as *mut _) } - } - fn sequence_copy( - in_seq: &rosidl_runtime_rs::Sequence, - out_seq: &mut rosidl_runtime_rs::Sequence, - ) -> bool { - // SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. - unsafe { builtin_interfaces__msg__Duration__Sequence__copy(in_seq, out_seq as *mut _) } - } - } - - impl rosidl_runtime_rs::Message for Duration { - type RmwMsg = Self; - fn into_rmw_message( - msg_cow: std::borrow::Cow<'_, Self>, - ) -> std::borrow::Cow<'_, Self::RmwMsg> { - msg_cow - } - fn from_rmw_message(msg: Self::RmwMsg) -> Self { - msg - } - } - - impl rosidl_runtime_rs::RmwMessage for Duration - where - Self: Sized, - { - const TYPE_NAME: &'static str = "builtin_interfaces/msg/Duration"; - fn get_type_support() -> *const std::ffi::c_void { - // SAFETY: No preconditions for this function. - unsafe { - rosidl_typesupport_c__get_message_type_support_handle__builtin_interfaces__msg__Duration() - } - } - } - - #[link(name = "builtin_interfaces__rosidl_typesupport_c")] - unsafe extern "C" { - fn rosidl_typesupport_c__get_message_type_support_handle__builtin_interfaces__msg__Time( - ) -> *const std::ffi::c_void; - } - - #[link(name = "builtin_interfaces__rosidl_generator_c")] - unsafe extern "C" { - fn builtin_interfaces__msg__Time__init(msg: *mut Time) -> bool; - fn builtin_interfaces__msg__Time__Sequence__init( - seq: *mut rosidl_runtime_rs::Sequence