| Crates.io | rustecal-service |
| lib.rs | rustecal-service |
| version | 0.1.6 |
| created_at | 2025-05-24 21:53:15.037882+00 |
| updated_at | 2025-08-25 21:08:40.520119+00 |
| description | Server/Client API for Eclipse eCAL |
| homepage | |
| repository | https://github.com/eclipse-ecal/rustecal |
| max_upload_size | |
| id | 1687773 |
| size | 38,169 |
rustecal-service provides a high-level RPC-style service server and client API, enabling request-response interactions with minimal boilerplate.
MethodInfo) and structured responses (ServiceResponse)Add to your workspace Cargo.toml:
[dependencies]
rustecal-service = "0.1"
use rustecal::{Ecal, EcalComponents, ServiceServer};
use rustecal::service::types::MethodInfo;
fn main() -> Result<(), Box<dyn std::error::Error>> {
Ecal::initialize(Some("mirror_server"), EcalComponents::DEFAULT, None)?;
let mut server = ServiceServer::new("mirror_service")?;
server.add_method("mirror", Box::new(|method: MethodInfo, req: &[u8]| {
let request_str = String::from_utf8_lossy(req);
println!("Received [{}] request: {}", method.method_name, request_str);
// Echo (mirror) the same bytes back
req.to_vec()
}))?;
println!("mirror_service is running…");
while Ecal::ok() {
std::thread::sleep(std::time::Duration::from_millis(500));
}
Ecal::finalize();
Ok(())
}
use rustecal::{Ecal, EcalComponents, ServiceClient, ServiceRequest};
fn main() -> Result<(), Box<dyn std::error::Error>> {
Ecal::initialize(Some("mirror_client"), EcalComponents::DEFAULT, None)?;
let client = ServiceClient::new("mirror_service")?;
let request_data = b"Hello, Service!";
let timeout = Some(500);
while Ecal::ok() {
let request = ServiceRequest {
payload: request_data.to_vec(),
};
// Call the "mirror" method
if let Some(response) = client.call("mirror", request, timeout) {
// Extract the echoed payload
let echoed = String::from_utf8_lossy(&response.payload);
println!("Received response: {}", echoed);
} else {
println!("Service call timed out.");
}
std::thread::sleep(std::time::Duration::from_millis(500));
}
Ecal::finalize();
Ok(())
}
ServiceServer
new(topic: &str) -> Result<Self, String>add_method(method: &str, callback: ServiceCallback) -> Result<(), String>ServiceClient
new(service_name: &str) -> Result<Self, String>call(method: &str, req: ServiceRequest, timeout_ms: Option<i32>) -> Option<ServiceResponse>rustecal-samples/service directory