fidl_next_protocol/
service.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Services are pretty tightly-coupled to our filesystem implementation, and so
6// the APIs for them reflect some of that coupling. Unlike server and client
7// handlers, service connectors and handlers accept `&self` and do not return a
8// future. In the future, it would be nice to experiment with
9
10/// A member connector for a FIDL service.
11pub trait ServiceConnector<T> {
12    /// The error type returned if the connector fails.
13    type Error;
14
15    /// Attempts to connect to the given service member.
16    fn connect_to_member(&self, member: &str, server_end: T) -> Result<(), Self::Error>;
17}
18
19/// A type which handles incoming service connections for a server.
20pub trait ServiceHandler<T> {
21    /// Handles a received connection request.
22    ///
23    /// The service cannot handle more connection requests until `on_connection` completes. If
24    /// `on_connection` should handle requests in parallel, it should spawn a new async task and
25    /// return.
26    fn on_connection(&self, member: &str, server_end: T);
27}