1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2023 Google LLC. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 #ifndef GOOGLE_PROTOBUF_COMPILER_RUST_ACCESSORS_ACCESSOR_CASE_H__ 9 #define GOOGLE_PROTOBUF_COMPILER_RUST_ACCESSORS_ACCESSOR_CASE_H__ 10 11 #include "absl/strings/string_view.h" 12 13 namespace google { 14 namespace protobuf { 15 namespace compiler { 16 namespace rust { 17 18 // GenerateAccessorMsgImpl is reused for all three types of $Msg$, $Msg$Mut and 19 // $Msg$View; this enum signifies which case we are handling so corresponding 20 // adjustments can be made (for example: to not emit any mutation accessors 21 // on $Msg$View). 22 enum class AccessorCase { 23 OWNED, 24 MUT, 25 VIEW, 26 }; 27 28 // Returns the `self` receiver type for a subfield view accessor. 29 absl::string_view ViewReceiver(AccessorCase accessor_case); 30 31 // Returns the lifetime of a subfield view accessor. 32 // Views are Copy, and so the full `'msg` lifetime can be used. 33 // Any `&self` or `&mut self` accessors need to use the lifetime of that 34 // borrow, which is referenced via `'_`. 35 // See b/314989133 for _mut accessors. 36 absl::string_view ViewLifetime(AccessorCase accessor_case); 37 38 } // namespace rust 39 } // namespace compiler 40 } // namespace protobuf 41 } // namespace google 42 43 #endif // GOOGLE_PROTOBUF_COMPILER_RUST_ACCESSORS_ACCESSOR_CASE_H__ 44