diff --git a/rclrs/Cargo.toml b/rclrs/Cargo.toml index f489ea3f0..93907a0f1 100644 --- a/rclrs/Cargo.toml +++ b/rclrs/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Esteve Fernandez ", "Nikolai Morin ().map_err(|e| format!("{}", e))) + .map(|id| if id != 99 { 99 } else { 98 }) + .expect("Error setting domain_id"); + let context: Context = Context::new_with_options([], InitOptions::new().with_domain_id(Some(domain_id))) - .unwrap(); + .unwrap_or_else(|error| panic!("Failed to create context: {}", error)); + let node_name = "test_publisher_names_and_types"; let node = Node::new(&context, node_name).unwrap(); // Test that the graph has no publishers let names_and_topics = node .get_publisher_names_and_types_by_node(node_name, "") - .unwrap(); - + .unwrap_or_else(|error| panic!("Failed to get publisher names and types: {}", error)); assert_eq!(names_and_topics.len(), 0); let num_publishers = node.count_publishers("/test").unwrap(); diff --git a/rclrs/src/parameter.rs b/rclrs/src/parameter.rs index c8a710eeb..6cbc35bf7 100644 --- a/rclrs/src/parameter.rs +++ b/rclrs/src/parameter.rs @@ -13,7 +13,7 @@ use crate::vendor::rcl_interfaces::msg::rmw::{ParameterType, ParameterValue as R use crate::{call_string_getter_with_rcl_node, rcl_bindings::*, Node, RclrsError}; use std::{ collections::{btree_map::Entry, BTreeMap}, - fmt::Debug, + fmt::{self, Debug, Display}, marker::PhantomData, sync::{Arc, Mutex, RwLock, Weak}, }; @@ -643,6 +643,34 @@ pub enum DeclarationError { /// An invalid range was provided to a parameter declaration (i.e. lower bound > higher bound). InvalidRange, } +impl Display for DeclarationError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + DeclarationError::AlreadyDeclared => write!( + f, + "Parameter was already declared and a new declaration was attempted" + ), + DeclarationError::NoValueAvailable => write!( + f, + "Parameter was declared as non optional but no value was available" + ), + DeclarationError::OverrideValueTypeMismatch => { + write!(f, "The override value that was provided has the wrong type") + } + DeclarationError::PriorValueTypeMismatch => write!( + f, + "The value that the parameter was already set to has the wrong type" + ), + DeclarationError::InitialValueOutOfRange => { + write!(f, "The initial value that was selected is out of range") + } + DeclarationError::InvalidRange => write!( + f, + "An invalid range was provided to a parameter declaration" + ), + } + } +} impl<'a> Parameters<'a> { /// Tries to read a parameter of the requested type. @@ -668,9 +696,9 @@ impl<'a> Parameters<'a> { /// Returns: /// * `Ok(())` if setting was successful. /// * [`Err(DeclarationError::TypeMismatch)`] if the type of the requested value is different - /// from the parameter's type. + /// from the parameter's type. /// * [`Err(DeclarationError::OutOfRange)`] if the requested value is out of the parameter's - /// range. + /// range. /// * [`Err(DeclarationError::ReadOnly)`] if the parameter is read only. pub fn set( &self, diff --git a/rclrs/src/parameter/range.rs b/rclrs/src/parameter/range.rs index 96f66d6e3..6a46d2ff0 100644 --- a/rclrs/src/parameter/range.rs +++ b/rclrs/src/parameter/range.rs @@ -32,7 +32,7 @@ impl From<()> for ParameterRanges { /// Usually only one of these ranges will be applied, but all have to be stored since: /// /// * A dynamic parameter can change its type at runtime, in which case a different range could be -/// applied. +/// applied. /// * Introspection through service calls requires all the ranges to be reported to the user. #[derive(Clone, Debug, Default)] pub struct ParameterRanges { diff --git a/rclrs/src/subscription/message_info.rs b/rclrs/src/subscription/message_info.rs index 010bf28ec..b36421d8e 100644 --- a/rclrs/src/subscription/message_info.rs +++ b/rclrs/src/subscription/message_info.rs @@ -7,23 +7,23 @@ use crate::rcl_bindings::*; /// To quote the `rmw` documentation: /// /// > The identifier uniquely identifies the publisher for the local context, but -/// it will not necessarily be the same identifier given in other contexts or processes -/// for the same publisher. -/// Therefore the identifier will uniquely identify the publisher within your application -/// but may disagree about the identifier for that publisher when compared to another -/// application. -/// Even with this limitation, when combined with the publisher sequence number it can -/// uniquely identify a message within your local context. -/// Publisher GIDs generated by the RMW implementation could collide at some point, in which -/// case it is not possible to distinguish which publisher sent the message. -/// The details of how GIDs are generated are RMW implementation dependent. +/// > it will not necessarily be the same identifier given in other contexts or processes +/// > for the same publisher. +/// > Therefore the identifier will uniquely identify the publisher within your application +/// > but may disagree about the identifier for that publisher when compared to another +/// > application. +/// > Even with this limitation, when combined with the publisher sequence number it can +/// > uniquely identify a message within your local context. +/// > Publisher GIDs generated by the RMW implementation could collide at some point, in which +/// > case it is not possible to distinguish which publisher sent the message. +/// > The details of how GIDs are generated are RMW implementation dependent. /// /// > It is possible the the RMW implementation needs to reuse a publisher GID, -/// due to running out of unique identifiers or some other constraint, in which case -/// the RMW implementation may document what happens in that case, but that -/// behavior is not defined here. -/// However, this should be avoided, if at all possible, by the RMW implementation, -/// and should be unlikely to happen in practice. +/// > due to running out of unique identifiers or some other constraint, in which case +/// > the RMW implementation may document what happens in that case, but that +/// > behavior is not defined here. +/// > However, this should be avoided, if at all possible, by the RMW implementation, +/// > and should be unlikely to happen in practice. #[derive(Clone, Debug, PartialEq, Eq)] pub struct PublisherGid { /// Bytes identifying a publisher in the RMW implementation. diff --git a/rclrs/src/wait.rs b/rclrs/src/wait.rs index 2ef99c026..243c9d857 100644 --- a/rclrs/src/wait.rs +++ b/rclrs/src/wait.rs @@ -329,7 +329,7 @@ impl WaitSet { /// /// - Passing a wait set with no wait-able items in it will return an error. /// - The timeout must not be so large so as to overflow an `i64` with its nanosecond - /// representation, or an error will occur. + /// representation, or an error will occur. /// /// This list is not comprehensive, since further errors may occur in the `rmw` or `rcl` layers. ///