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_ENUM_H__ 9 #define GOOGLE_PROTOBUF_COMPILER_RUST_ENUM_H__ 10 11 #include <cstdint> 12 #include <string> 13 #include <utility> 14 #include <vector> 15 16 #include "absl/strings/string_view.h" 17 #include "absl/types/span.h" 18 #include "google/protobuf/compiler/rust/context.h" 19 #include "google/protobuf/descriptor.h" 20 21 namespace google { 22 namespace protobuf { 23 namespace compiler { 24 namespace rust { 25 26 // Generates code for a particular enum in `.pb.rs`. 27 void GenerateEnumDefinition(Context& ctx, const EnumDescriptor& desc); 28 29 // An enum value with a unique number and any aliases for it. 30 struct RustEnumValue { 31 // The canonical CamelCase name in Rust. 32 std::string name; 33 int32_t number; 34 std::vector<std::string> aliases; 35 }; 36 37 // Returns the list of rust enum variants to produce, along with their aliases. 38 // Performs name normalization, deduplication, and alias determination. 39 // The `number` and `name` of every returned `RustEnumValue` is unique. 40 std::vector<RustEnumValue> EnumValues( 41 absl::string_view enum_name, 42 absl::Span<const std::pair<absl::string_view, int32_t>> values); 43 44 } // namespace rust 45 } // namespace compiler 46 } // namespace protobuf 47 } // namespace google 48 49 #endif // GOOGLE_PROTOBUF_COMPILER_RUST_ENUM_H__ 50