9 releases

Uses new Rust 2024

0.1.8 Aug 25, 2025
0.1.7 Jul 28, 2025
0.1.6 Jun 20, 2025
0.1.4 May 24, 2025

#3 in #ecal

Download history 24/week @ 2025-09-24 38/week @ 2025-10-01 48/week @ 2025-10-08 37/week @ 2025-10-15 24/week @ 2025-10-22 1/week @ 2025-11-12 7/week @ 2025-11-19 34/week @ 2025-12-10 50/week @ 2025-12-17 19/week @ 2025-12-31 107/week @ 2026-01-07

179 downloads per month
Used in 5 crates

Apache-2.0

72KB
1K SLoC

rustecal-pubsub

rustecal-pubsub provides a high-level, type-safe Publisher/Subscriber API on top of eCAL’s raw FFI and Core API, enabling Rust applications to send and receive structured messages with minimal boilerplate.

Features

  • Untyped Pub/Sub for raw buffers when needed
  • Typed Pub/Sub via TypedPublisher<T> and TypedSubscriber<T>
  • Support for arbitrary message types implementing the PublisherMessage and SubscriberMessage traits
  • Metadata propagation: topics carry encoding, type name, and optional descriptor

Requirements

  • Rust 1.60 or later
  • Eclipse eCAL C/C++ library v6.0 or later installed and accessible on your system

Installation

Add to your Cargo.toml:

[dependencies]
rustecal-pubsub = "0.1"

Quickstart

Typed Publisher Example

use rustecal::{Ecal, EcalComponents, TypedPublisher};
use rustecal_types_string::StringMessage;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    Ecal::initialize(Some("string publisher"), EcalComponents::DEFAULT, None)?;

    let publisher = TypedPublisher::<StringMessage>::new("hello")?;

    while Ecal::ok() {
        let message = StringMessage { data: "Hello from Rust".into() };
        publisher.send(&message, Timestamp::Auto);

        std::thread::sleep(std::time::Duration::from_millis(500));
    }

    Ecal::finalize();
    Ok(())
}

Typed Subscriber Example

use rustecal::{Ecal, EcalComponents, TypedSubscriber};
use rustecal_types_string::StringMessage;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    Ecal::initialize(Some("string subscriber"), EcalComponents::DEFAULT, None)?;

    let mut subscriber = TypedSubscriber::<StringMessage>::new("hello")?;
    subscriber.set_callback(|message| {
        println!("Received: {}", message.payload.data)
    });

    while Ecal::ok() {
        std::thread::sleep(std::time::Duration::from_millis(500));
    }

    Ecal::finalize();
    Ok(())
}

Traits Reference

  • PublisherMessage: Defines datatype() and to_bytes() for a message type.
  • SubscriberMessage: Defines datatype() and from_bytes() for reconstructing a message.

Implement these traits to integrate custom types or leverage helper crates like rustecal-types-protobuf or rustecal-types-serde.

Advanced Usage

  • Untyped Pub/Sub: Use rustecal_pubsub::Publisher and Subscriber for raw buffers.
  • Metadata Inspection: Retrieve topic metadata via get_data_type_information().
  • Message-format support: Combine with rustecal-types-bytes, rustecal-types-string, rustecal-types-protobuf for Bytes, String, and Protobuf.
  • Message-format support: Combine with rustecal-types-serde for JSON, CBOR, and MessagePack.

For more examples, see the rustecal-samples/pubsub.

Dependencies

~225–770KB
~17K SLoC