#websocket #json #ros #async

roslibrust_codegen

An library for generating rust type definitions from ROS IDL files

15 breaking releases

new 0.19.0 Jan 14, 2026
0.18.0 Nov 25, 2025
0.17.0 Nov 18, 2025
0.15.0 Jun 20, 2025
0.2.0 Sep 1, 2022

#131 in Robotics

Download history 909/week @ 2025-09-25 990/week @ 2025-10-02 1092/week @ 2025-10-09 768/week @ 2025-10-16 1037/week @ 2025-10-23 323/week @ 2025-10-30 453/week @ 2025-11-06 508/week @ 2025-11-13 275/week @ 2025-11-20 263/week @ 2025-11-27 475/week @ 2025-12-04 340/week @ 2025-12-11 275/week @ 2025-12-18 100/week @ 2025-12-25 681/week @ 2026-01-01 1169/week @ 2026-01-08

2,318 downloads per month
Used in 7 crates (4 directly)

MIT license

225KB
4K SLoC

RosLibRust

Noetic Galactic Humble Iron Kilted Rolling License:MIT

Documentation about the crate is on docs.rs, extended guides can be found on roslibrust.github.io

An async rust library for interfacing with ROS1 and ROS2, built on Tokio.

  • One Trait Based API - Write your behavior once and use it with any backend! Select the backend you want to use at compile time.
  • Pure Rust - No ROS1 or ROS2 dependencies or installation required! Compile time message generation from .msg/.srv files.

This allows writing generic behaviors like:

# use roslibrust_test::ros1::*;
use roslibrust::{TopicProvider, Publish, Subscribe};

async fn relay<T: TopicProvider>(ros: T) -> roslibrust::Result<()> {
    let mut subscriber = ros.subscribe::<std_msgs::String>("/in").await?;
    let mut publisher = ros.advertise::<std_msgs::String>("/out").await?;
    while let Ok(msg) = subscriber.next().await {
        println!("Got message: {}", msg.data);
        publisher.publish(&msg).await?;
    }
    Ok(())
}

#[tokio::main]
async fn main() -> roslibrust::Result<()> {
    // Relay messages over a native ROS2 connection using Zenoh
    // #[cfg(feature = "ros2")]
    // {
    // let ros = roslibrust::ros2::NodeHandle::new("http://localhost:11311", "relay").await?;
    // relay(ros).await?;
    // }

    // Relay messages over a native ROS1 connection via TCPROS
    #[cfg(feature = "ros1")]
    {
    let ros = roslibrust::ros1::NodeHandle::new("http://localhost:11311", "relay").await?;
    relay(ros).await?;
    }

    // Relay messages over a zenoh connection compatible with zenoh-ros1-plugin / zenoh-ros1-bridge
    #[cfg(feature = "zenoh")]
    {
    let ros = roslibrust::zenoh::ZenohClient::new(zenoh::open(zenoh::Config::default()).await.unwrap());
    relay(ros).await?;
    }

    // Relay messages over a rosbridge_server connection with either ROS1 or ROS2!
    #[cfg(feature = "rosbridge")]
    {
    let ros = roslibrust::rosbridge::ClientHandle::new("ws://localhost:9090").await?;
    relay(ros).await?;
    }

    // Relay messages over a mock ROS connection for testing
    #[cfg(feature = "mock")]
    {
    let ros = roslibrust::mock::MockRos::new();
    relay(ros).await?;
    }

    Ok(())
}

All of this is backed by common traits for ROS messages, topics, and services. roslibrust_codegen provides generation of Rust types from both ROS1 and ROS2 .msg/.srv files and roslibrust_codegen_macro provides a convenient macro for generating these types:

// Will generate types from all packages in ROS_PACKAGE_PATH 
roslibrust_codegen_macro::find_and_generate_ros_messages!();

If you want to see what the generated code looks like checkout our generated messages in our test crate. While the macro is useful for getting started, we recommend using roslibrust_codegen with a build.rs as shown in example_package. This allows cargo to know when message files are edited and automatically re-generate the code.

Getting Started / Examples

Contributing

Contribution through reporting of issues encountered and implementation in PRs is welcome! Before landing a large PR with lots of code implemented, please open an issue if there isn't a relevant one already available and chat with a maintainer to make sure the design fits well with all supported platforms and any in-progress implementation efforts.

We uphold the rust lang Code of Conduct.

Minimum Supported Rust Version / MSRV

MSRV is currently 1.85 to support edition 2024.

Dependencies

~5–9.5MB
~185K SLoC