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