diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index 42ac613da1..66b59566db 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -38,6 +38,8 @@ fn test_default_accessors() { let msg = TestAllTypes::new(); assert_eq!(msg.default_int32(), 41); assert_eq!(msg.default_int64(), 42); + assert_eq!(msg.default_uint32(), 43); + assert_eq!(msg.default_uint64(), 44); assert_eq!(msg.default_bool(), true); } @@ -72,6 +74,36 @@ fn test_optional_int64_accessors() { assert_eq!(msg.optional_int64(), 0); } +#[test] +fn test_optional_uint32_accessors() { + let mut msg = TestAllTypes::new(); + assert_eq!(msg.optional_uint32_opt(), None); + assert_eq!(msg.optional_uint32(), 0); + + msg.optional_uint32_set(Some(9001)); + assert_eq!(msg.optional_uint32_opt(), Some(9001)); + assert_eq!(msg.optional_uint32(), 9001); + + msg.optional_uint32_set(None); + assert_eq!(msg.optional_uint32_opt(), None); + assert_eq!(msg.optional_uint32(), 0); +} + +#[test] +fn test_optional_uint64_accessors() { + let mut msg = TestAllTypes::new(); + assert_eq!(msg.optional_uint64_opt(), None); + assert_eq!(msg.optional_uint64(), 0); + + msg.optional_uint64_set(Some(42)); + assert_eq!(msg.optional_uint64_opt(), Some(42)); + assert_eq!(msg.optional_uint64(), 42); + + msg.optional_uint64_set(None); + assert_eq!(msg.optional_uint64_opt(), None); + assert_eq!(msg.optional_uint64(), 0); +} + #[test] fn test_optional_bool_accessors() { let mut msg = TestAllTypes::new(); diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.cc b/src/google/protobuf/compiler/rust/accessors/accessors.cc index 115f5fc2ec..fd16be7e9c 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.cc +++ b/src/google/protobuf/compiler/rust/accessors/accessors.cc @@ -51,6 +51,8 @@ std::unique_ptr AccessorGenerator::For( switch (field.desc().type()) { case FieldDescriptor::TYPE_INT32: case FieldDescriptor::TYPE_INT64: + case FieldDescriptor::TYPE_UINT32: + case FieldDescriptor::TYPE_UINT64: case FieldDescriptor::TYPE_BOOL: if (field.desc().is_repeated()) return nullptr; return ForSingularScalar(field); diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index 1674072f6e..2e62818a84 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -114,6 +114,10 @@ absl::string_view PrimitiveRsTypeName(Context field) { return "i32"; case FieldDescriptor::TYPE_INT64: return "i64"; + case FieldDescriptor::TYPE_UINT32: + return "u32"; + case FieldDescriptor::TYPE_UINT64: + return "u64"; case FieldDescriptor::TYPE_BYTES: return "&[u8]"; default: @@ -131,6 +135,8 @@ bool IsSupportedFieldType(Context field) { (field.desc().type() == FieldDescriptor::TYPE_BOOL || field.desc().type() == FieldDescriptor::TYPE_INT32 || field.desc().type() == FieldDescriptor::TYPE_INT64 || + field.desc().type() == FieldDescriptor::TYPE_UINT32 || + field.desc().type() == FieldDescriptor::TYPE_UINT64 || field.desc().type() == FieldDescriptor::TYPE_BYTES); }