pub trait ServiceServerTrait {
type Error;
// Required methods
fn try_recv_request<'a>(
&mut self,
buf: &'a mut [u8],
) -> Result<Option<ServiceRequest<'a>>, Self::Error>;
fn send_reply(
&mut self,
sequence_number: i64,
data: &[u8],
) -> Result<(), Self::Error>;
// Provided methods
fn has_request(&self) -> bool { ... }
fn register_waker(&self, _waker: &Waker) { ... }
fn handle_request<S: RosService>(
&mut self,
req_buf: &mut [u8],
reply_buf: &mut [u8],
handler: impl FnOnce(&S::Request) -> S::Reply,
) -> Result<bool, Self::Error>
where Self::Error: From<TransportError> { ... }
fn handle_request_boxed<S: RosService>(
&mut self,
req_buf: &mut [u8],
reply_buf: &mut [u8],
handler: impl FnOnce(&S::Request) -> Box<S::Reply>,
) -> Result<bool, Self::Error>
where Self::Error: From<TransportError> { ... }
}Expand description
Service server trait for handling requests.
§Threading
&mut self on try_recv_request and send_reply — the executor
owns the server while a request is being handled. Handler bodies
run synchronously on the executor thread; long handlers should
dispatch work to a worker queue and reply later via the recorded
sequence_number.
§Calling pattern
- Executor calls
try_recv_request(buf). - If
Some(req)returned, decode, run handler, encode reply. send_reply(req.sequence_number, &reply_buf).
sequence_number is the canonical request → reply correlation
token; backends derive it from the wire-level metadata (zenoh
query id, DDS sample identity).
Required Associated Types§
Required Methods§
Sourcefn try_recv_request<'a>(
&mut self,
buf: &'a mut [u8],
) -> Result<Option<ServiceRequest<'a>>, Self::Error>
fn try_recv_request<'a>( &mut self, buf: &'a mut [u8], ) -> Result<Option<ServiceRequest<'a>>, Self::Error>
Try to receive a service request into buf (non-blocking).
On success returns a ServiceRequest that borrows from
buf. The borrow is released when the returned struct is
dropped — typically before send_reply is called, since
send_reply takes &mut self.
Provided Methods§
Sourcefn has_request(&self) -> bool
fn has_request(&self) -> bool
Check if a request is available without consuming it.
Non-destructive. Default returns true (always assume one
may be available); backends should override with a real
check.
Sourcefn register_waker(&self, _waker: &Waker)
fn register_waker(&self, _waker: &Waker)
Phase 122.3.c.6.e — register a Waker for event-driven
service servers. Mirrors the matching method on
SubscriberTrait / ServiceClientTrait. Backends that
surface incoming-request notifications wake waker when
has_request() flips true. Default: no-op (backends without
wake support ignore — caller falls back to polling).
Sourcefn handle_request<S: RosService>(
&mut self,
req_buf: &mut [u8],
reply_buf: &mut [u8],
handler: impl FnOnce(&S::Request) -> S::Reply,
) -> Result<bool, Self::Error>
fn handle_request<S: RosService>( &mut self, req_buf: &mut [u8], reply_buf: &mut [u8], handler: impl FnOnce(&S::Request) -> S::Reply, ) -> Result<bool, Self::Error>
Handle a service request with typed messages
Sourcefn handle_request_boxed<S: RosService>(
&mut self,
req_buf: &mut [u8],
reply_buf: &mut [u8],
handler: impl FnOnce(&S::Request) -> Box<S::Reply>,
) -> Result<bool, Self::Error>
fn handle_request_boxed<S: RosService>( &mut self, req_buf: &mut [u8], reply_buf: &mut [u8], handler: impl FnOnce(&S::Request) -> Box<S::Reply>, ) -> Result<bool, Self::Error>
Handle a service request where the handler returns Box<S::Reply>
Identical to handle_request but the handler returns a heap-allocated reply.
This is needed for services with large response types (e.g., parameter services
where Vec<ParameterValue, 64> is ~1MB+) that would overflow the stack.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.