rocketmq_error/projection.rs
1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::CliSpec;
16use crate::GrpcSpec;
17use crate::HttpSpec;
18use crate::RemotingSpec;
19
20/// Explicit boundary projections owned by an error descriptor.
21///
22/// Every catalog declaration supplies all four projections. The catalog does
23/// not infer protocol behavior from a canonical condition, and callers cannot
24/// construct or override projection metadata outside this crate.
25///
26/// ```compile_fail
27/// use rocketmq_error::ProjectionSpec;
28///
29/// let projection = ProjectionSpec {
30/// remoting: todo!(),
31/// grpc: todo!(),
32/// http: todo!(),
33/// cli: todo!(),
34/// };
35/// ```
36#[derive(Debug, Clone, Copy, PartialEq, Eq)]
37pub struct ProjectionSpec {
38 remoting: RemotingSpec,
39 grpc: GrpcSpec,
40 http: HttpSpec,
41 cli: CliSpec,
42}
43
44impl ProjectionSpec {
45 #[inline]
46 pub(crate) const fn new(remoting: RemotingSpec, grpc: GrpcSpec, http: HttpSpec, cli: CliSpec) -> Self {
47 Self {
48 remoting,
49 grpc,
50 http,
51 cli,
52 }
53 }
54
55 /// Returns the RocketMQ remoting response projection.
56 #[inline]
57 pub const fn remoting(&self) -> RemotingSpec {
58 self.remoting
59 }
60
61 /// Returns the gRPC payload and transport-status projection.
62 #[inline]
63 pub const fn grpc(&self) -> GrpcSpec {
64 self.grpc
65 }
66
67 /// Returns the HTTP status projection.
68 #[inline]
69 pub const fn http(&self) -> HttpSpec {
70 self.http
71 }
72
73 /// Returns the CLI exit-code projection.
74 #[inline]
75 pub const fn cli(&self) -> CliSpec {
76 self.cli
77 }
78}