google_cloud_wkt/empty.rs
1// Copyright 2024 Google LLC
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// https://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
15/// A generic empty message that you can re-use to avoid defining duplicated
16/// empty messages in your APIs. A typical example is to use it as the request
17/// or the response type of an API method. For instance:
18///
19/// ```norust
20/// service Foo {
21/// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
22/// }
23/// ```
24///
25#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
26pub struct Empty {}
27
28impl crate::message::Message for Empty {
29 fn typename() -> &'static str {
30 "type.googleapis.com/google.protobuf.Empty"
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37 use serde_json::json;
38 type Result = std::result::Result<(), Box<dyn std::error::Error>>;
39
40 #[test]
41 fn serialize() -> Result {
42 let empty = Empty::default();
43 let got = serde_json::to_value(empty)?;
44 assert_eq!(json!({}), got);
45 Ok(())
46 }
47
48 #[test]
49 fn deserialize() -> Result {
50 let got = serde_json::from_value(json!({}))?;
51 assert_eq!(Empty::default(), got);
52 Ok(())
53 }
54}