Skip to content

Commit

Permalink
Switch generic examples to being generic over Ros trait
Browse files Browse the repository at this point in the history
  • Loading branch information
carter committed Jan 9, 2025
1 parent 239ab36 commit dd21245
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion example_package/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use roslibrust::Publish;

// Writing a simple behavior that uses the generic traits from roslibrust
// and the generated types from the macro above.
async fn pub_counter(ros: impl roslibrust::TopicProvider) {
async fn pub_counter(ros: impl roslibrust::Ros) {
let publisher = ros
.advertise::<std_msgs::Int16>("example_counter")
.await
Expand Down
2 changes: 1 addition & 1 deletion example_package_macro/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ roslibrust::find_and_generate_ros_messages!(

// Writing a simple behavior that uses the generic traits from roslibrust
// and the generated types from the macro above.
async fn pub_counter(ros: impl roslibrust::TopicProvider) {
async fn pub_counter(ros: impl roslibrust::Ros) {
let publisher = ros
.advertise::<std_msgs::Int16>("example_counter")
.await
Expand Down
6 changes: 3 additions & 3 deletions roslibrust/examples/generic_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ roslibrust_codegen_macro::find_and_generate_ros_messages!("assets/ros1_common_in
#[cfg(all(feature = "rosbridge", feature = "ros1"))]
#[tokio::main]
async fn main() {
use roslibrust::{Publish, Subscribe, TopicProvider};
use roslibrust::{Publish, Ros, Subscribe};
env_logger::init();

// TopicProvider cannot be an "Object Safe Trait" due to its generic parameters
Expand All @@ -21,13 +21,13 @@ async fn main() {
// single application. The critical part is to make TopicProvider a
// generic type on you Node.

struct MyNode<T: TopicProvider> {
struct MyNode<T: Ros> {
ros: T,
name: String,
}

// Basic example of a node that publishes and subscribes to itself
impl<T: TopicProvider> MyNode<T> {
impl<T: Ros> MyNode<T> {
async fn run(self) {
let publisher = self
.ros
Expand Down
6 changes: 3 additions & 3 deletions roslibrust/examples/generic_client_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ roslibrust_codegen_macro::find_and_generate_ros_messages!("assets/ros1_common_in
#[tokio::main]
async fn main() {
// Important to bring these traits into scope so we can use them
use roslibrust::{Service, ServiceProvider};
use roslibrust::{Ros, Service};
env_logger::init();

// TopicProvider cannot be an "Object Safe Trait" due to its generic parameters
Expand All @@ -20,13 +20,13 @@ async fn main() {
// single application. The critical part is to make TopicProvider a
// generic type on you Node.

struct MyNode<T: ServiceProvider + 'static> {
struct MyNode<T: Ros> {
ros: T,
}

// Basic example of a node that publishes and subscribes to itself
// This node will work with any backend
impl<T: ServiceProvider> MyNode<T> {
impl<T: Ros> MyNode<T> {
fn handle_service(
_request: std_srvs::SetBoolRequest,
) -> Result<std_srvs::SetBoolResponse, Box<dyn std::error::Error + Send + Sync>> {
Expand Down
1 change: 1 addition & 0 deletions roslibrust/examples/generic_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl RosMessageType for GenericHeader {
}

/// Sets up a subscriber that could get either of two versions of a message
/// Note this is currently only supported by the rosbridge backend as this behavior relies on serde_json's fallback capabilities
#[cfg(feature = "rosbridge")]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down

0 comments on commit dd21245

Please sign in to comment.