grpc_core/method.rs
1//! Static RPC routing and cardinality descriptions.
2
3/// Message multiplicity in each direction of an RPC.
4#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
5pub enum RpcCardinality {
6 /// One request and one response.
7 Unary,
8 /// One request and a stream of responses.
9 ServerStreaming,
10 /// A stream of requests and one response.
11 ClientStreaming,
12 /// Independent request and response streams.
13 BidiStreaming,
14}
15
16/// Static routing information emitted by service definitions.
17///
18/// `path` is the canonical, case-sensitive HTTP/2 path in the form
19/// `/package.Service/Method`. The service definition owns its validity.
20#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
21pub struct MethodDescriptor {
22 /// Canonical HTTP/2 request path.
23 pub path: &'static str,
24 /// Request and response message multiplicity.
25 pub cardinality: RpcCardinality,
26}
27
28impl MethodDescriptor {
29 /// Describes a method using its canonical path and message multiplicity.
30 #[must_use]
31 pub const fn new(path: &'static str, cardinality: RpcCardinality) -> Self {
32 Self { path, cardinality }
33 }
34}