fidl_next_bind/protocol.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
5use fidl_next_protocol::{Flexibility, Transport};
6
7/// A FIDL protocol which has associated connection handles.
8///
9/// # Safety
10///
11/// The associated `Client` and `Server` types must be `#[repr(transparent)]`
12/// wrappers around `Client<T>` and `Server<T>` respectively.
13pub unsafe trait HasConnectionHandles<T> {
14 /// The client for the protocol. It must be a `#[repr(transparent)]` wrapper
15 /// around `Client<T>`.
16 type Client;
17
18 /// The server for the protocol. It must be a `#[repr(transparent)]` wrapper
19 /// around `Server<T>`.
20 type Server;
21}
22
23/// A discoverable FIDL protocol.
24pub trait Discoverable {
25 /// The service name to use to connect to this discoverable protocol.
26 const PROTOCOL_NAME: &'static str;
27}
28
29/// A method of a protocol.
30pub trait Method {
31 /// The ordinal associated with the method;
32 const ORDINAL: u64;
33
34 /// The flexibility of the method.
35 const FLEXIBILITY: Flexibility;
36
37 /// The protocol the method is a member of.
38 type Protocol;
39
40 /// The request payload for the method.
41 type Request;
42}
43
44/// A protocol method which has a response.
45pub trait TwoWayMethod: Method {
46 /// The response payload for the method.
47 type Response;
48}
49
50/// A method which can be responded to with a single value.
51///
52/// For methods which return a result, this method implicitly returns `Ok` of
53/// the given response.
54pub trait Respond<R> {
55 /// The returned response type.
56 type Output;
57
58 /// Makes a response from the given input.
59 fn respond(response: R) -> Self::Output;
60}
61
62/// A method which can be responded `Err` to with a single value.
63pub trait RespondErr<R> {
64 /// The returned response type.
65 type Output;
66
67 /// Makes an `Err` response from the given input.
68 fn respond_err(response: R) -> Self::Output;
69}
70
71/// A protocol which has a default transport type.
72pub trait HasTransport {
73 /// The default transport type for this protocol.
74 type Transport: Transport;
75}