| Crates.io | rustecal-pubsub |
| lib.rs | rustecal-pubsub |
| version | 0.1.8 |
| created_at | 2025-05-24 14:36:31.439394+00 |
| updated_at | 2025-08-25 21:08:16.17993+00 |
| description | Publish/Subscribe API for Eclipse eCAL |
| homepage | |
| repository | https://github.com/eclipse-ecal/rustecal |
| max_upload_size | |
| id | 1687500 |
| size | 54,669 |
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.
TypedPublisher<T> and TypedSubscriber<T>PublisherMessage and SubscriberMessage traitsAdd to your Cargo.toml:
[dependencies]
rustecal-pubsub = "0.1"
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(())
}
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(())
}
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.
rustecal_pubsub::Publisher and Subscriber for raw buffers.get_data_type_information().rustecal-types-bytes, rustecal-types-string, rustecal-types-protobuf for Bytes, String, and Protobuf.rustecal-types-serde for JSON, CBOR, and MessagePack.For more examples, see the rustecal-samples/pubsub.