From 7e47fc3e39df81df18e2838a38841a57f2d28aa4 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Mar 2024 08:46:59 -0700 Subject: [PATCH] Remove the _mut() accessors from primitive fields (both explicit presence where they were FieldEntry and implicit presence where they were PrimitiveMut). PiperOrigin-RevId: 615792730 --- rust/test/shared/accessors_map_test.rs | 2 +- rust/test/shared/accessors_proto3_test.rs | 98 +--- rust/test/shared/accessors_repeated_test.rs | 4 +- rust/test/shared/accessors_test.rs | 435 ++++-------------- rust/test/shared/edition2023_test.rs | 10 +- rust/test/shared/simple_nested_test.rs | 63 +-- .../rust/accessors/singular_scalar.cc | 72 --- 7 files changed, 97 insertions(+), 587 deletions(-) diff --git a/rust/test/shared/accessors_map_test.rs b/rust/test/shared/accessors_map_test.rs index 930b1e5fe7..be22aebf69 100644 --- a/rust/test/shared/accessors_map_test.rs +++ b/rust/test/shared/accessors_map_test.rs @@ -167,7 +167,7 @@ macro_rules! generate_map_with_msg_values_tests { // this block makes sure `insert` copies/moves, not borrows. { let mut msg_val = TestAllTypes::new(); - msg_val.optional_int32_mut().set(1001); + msg_val.set_optional_int32(1001); assert_that!( msg .[< map_ $k_field _all_types_mut >]() diff --git a/rust/test/shared/accessors_proto3_test.rs b/rust/test/shared/accessors_proto3_test.rs index c60a7c564c..f9af74a453 100644 --- a/rust/test/shared/accessors_proto3_test.rs +++ b/rust/test/shared/accessors_proto3_test.rs @@ -8,7 +8,6 @@ /// Tests covering accessors for singular bool, int32, int64, and bytes fields /// on proto3. use googletest::prelude::*; -use matchers::{is_set, is_unset}; use protobuf::Optional; use unittest_proto3::{TestAllTypes, TestAllTypes_}; use unittest_proto3_optional::{TestProto3Optional, TestProto3Optional_}; @@ -17,38 +16,27 @@ use unittest_proto3_optional::{TestProto3Optional, TestProto3Optional_}; fn test_fixed32_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.optional_fixed32(), eq(0)); - assert_that!(msg.optional_fixed32_mut().get(), eq(0)); msg.set_optional_fixed32(42); - assert_that!(msg.optional_fixed32_mut().get(), eq(42)); assert_that!(msg.optional_fixed32(), eq(42)); msg.set_optional_fixed32(u32::default()); assert_that!(msg.optional_fixed32(), eq(0)); - assert_that!(msg.optional_fixed32_mut().get(), eq(0)); - msg.optional_fixed32_mut().set(43); + msg.set_optional_fixed32(43); assert_that!(msg.optional_fixed32(), eq(43)); - assert_that!(msg.optional_fixed32_mut().get(), eq(43)); } #[test] fn test_bool_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.optional_bool(), eq(false)); - assert_that!(msg.optional_bool_mut().get(), eq(false)); msg.set_optional_bool(true); assert_that!(msg.optional_bool(), eq(true)); - assert_that!(msg.optional_bool_mut().get(), eq(true)); msg.set_optional_bool(bool::default()); assert_that!(msg.optional_bool(), eq(false)); - assert_that!(msg.optional_bool_mut().get(), eq(false)); - - msg.optional_bool_mut().set(true); - assert_that!(msg.optional_bool(), eq(true)); - assert_that!(msg.optional_bool_mut().get(), eq(true)); } #[test] @@ -57,26 +45,18 @@ fn test_bytes_accessors() { // Note: even though it's named 'optional_bytes', the field is actually not // proto3 optional, so it does not support presence. assert_that!(*msg.optional_bytes(), empty()); - assert_that!(*msg.optional_bytes_mut().get(), empty()); msg.set_optional_bytes(b"accessors_test"); assert_that!(msg.optional_bytes(), eq(b"accessors_test")); - assert_that!(msg.optional_bytes_mut().get(), eq(b"accessors_test")); { let s = Vec::from(&b"hello world"[..]); msg.set_optional_bytes(&s[..]); } assert_that!(msg.optional_bytes(), eq(b"hello world")); - assert_that!(msg.optional_bytes_mut().get(), eq(b"hello world")); - - msg.optional_bytes_mut().clear(); - assert_that!(*msg.optional_bytes(), empty()); - assert_that!(*msg.optional_bytes_mut().get(), empty()); msg.set_optional_bytes(b""); assert_that!(*msg.optional_bytes(), empty()); - assert_that!(*msg.optional_bytes_mut().get(), empty()); } #[test] @@ -84,8 +64,6 @@ fn test_optional_bytes_accessors() { let mut msg = TestProto3Optional::new(); assert_that!(*msg.optional_bytes(), empty()); assert_that!(msg.optional_bytes_opt(), eq(Optional::Unset(&b""[..]))); - assert_that!(*msg.optional_bytes_mut().get(), empty()); - assert_that!(msg.optional_bytes_mut(), is_unset()); { let s = Vec::from(&b"hello world"[..]); @@ -93,36 +71,14 @@ fn test_optional_bytes_accessors() { } assert_that!(msg.optional_bytes(), eq(b"hello world")); assert_that!(msg.optional_bytes_opt(), eq(Optional::Set(&b"hello world"[..]))); - assert_that!(msg.optional_bytes_mut(), is_set()); - assert_that!(msg.optional_bytes_mut().get(), eq(b"hello world")); - - msg.optional_bytes_mut().or_default().set(b"accessors_test"); - assert_that!(msg.optional_bytes(), eq(b"accessors_test")); - assert_that!(msg.optional_bytes_opt(), eq(Optional::Set(&b"accessors_test"[..]))); - assert_that!(msg.optional_bytes_mut(), is_set()); - assert_that!(msg.optional_bytes_mut().get(), eq(b"accessors_test")); - assert_that!(msg.optional_bytes_mut().or_default().get(), eq(b"accessors_test")); - - msg.optional_bytes_mut().clear(); - assert_that!(*msg.optional_bytes(), empty()); - assert_that!(msg.optional_bytes_opt(), eq(Optional::Unset(&b""[..]))); - assert_that!(msg.optional_bytes_mut(), is_unset()); msg.set_optional_bytes(b""); assert_that!(*msg.optional_bytes(), empty()); assert_that!(msg.optional_bytes_opt(), eq(Optional::Set(&b""[..]))); - msg.optional_bytes_mut().clear(); - msg.optional_bytes_mut().or_default(); - assert_that!(*msg.optional_bytes(), empty()); - assert_that!(msg.optional_bytes_opt(), eq(Optional::Set(&b""[..]))); - - msg.optional_bytes_mut().or_default().set(b"\xffbinary\x85non-utf8"); + msg.set_optional_bytes(b"\xffbinary\x85non-utf8"); assert_that!(msg.optional_bytes(), eq(b"\xffbinary\x85non-utf8")); assert_that!(msg.optional_bytes_opt(), eq(Optional::Set(&b"\xffbinary\x85non-utf8"[..]))); - assert_that!(msg.optional_bytes_mut(), is_set()); - assert_that!(msg.optional_bytes_mut().get(), eq(b"\xffbinary\x85non-utf8")); - assert_that!(msg.optional_bytes_mut().or_default().get(), eq(b"\xffbinary\x85non-utf8")); } #[test] @@ -131,26 +87,18 @@ fn test_string_accessors() { // Note: even though it's named 'optional_string', the field is actually not // proto3 optional, so it does not support presence. assert_that!(*msg.optional_string().as_bytes(), empty()); - assert_that!(*msg.optional_string_mut().get().as_bytes(), empty()); msg.set_optional_string("accessors_test"); assert_that!(msg.optional_string(), eq("accessors_test")); - assert_that!(msg.optional_string_mut().get(), eq("accessors_test")); { let s = String::from("hello world"); msg.set_optional_string(&s[..]); } assert_that!(msg.optional_string(), eq("hello world")); - assert_that!(msg.optional_string_mut().get(), eq("hello world")); - - msg.optional_string_mut().clear(); - assert_that!(*msg.optional_string().as_bytes(), empty()); - assert_that!(*msg.optional_string_mut().get().as_bytes(), empty()); msg.set_optional_string(""); assert_that!(*msg.optional_string().as_bytes(), empty()); - assert_that!(*msg.optional_string_mut().get().as_bytes(), empty()); } #[test] @@ -158,8 +106,6 @@ fn test_optional_string_accessors() { let mut msg = TestProto3Optional::new(); assert_that!(*msg.optional_string().as_bytes(), empty()); assert_that!(msg.optional_string_opt(), eq(Optional::Unset("".into()))); - assert_that!(*msg.optional_string_mut().get().as_bytes(), empty()); - assert_that!(msg.optional_string_mut(), is_unset()); { let s = String::from("hello world"); @@ -167,29 +113,14 @@ fn test_optional_string_accessors() { } assert_that!(msg.optional_string(), eq("hello world")); assert_that!(msg.optional_string_opt(), eq(Optional::Set("hello world".into()))); - assert_that!(msg.optional_string_mut(), is_set()); - assert_that!(msg.optional_string_mut().get(), eq("hello world")); - msg.optional_string_mut().or_default().set("accessors_test"); + msg.set_optional_string("accessors_test"); assert_that!(msg.optional_string(), eq("accessors_test")); assert_that!(msg.optional_string_opt(), eq(Optional::Set("accessors_test".into()))); - assert_that!(msg.optional_string_mut(), is_set()); - assert_that!(msg.optional_string_mut().get(), eq("accessors_test")); - assert_that!(msg.optional_string_mut().or_default().get(), eq("accessors_test")); - - msg.optional_string_mut().clear(); - assert_that!(*msg.optional_string().as_bytes(), empty()); - assert_that!(msg.optional_string_opt(), eq(Optional::Unset("".into()))); - assert_that!(msg.optional_string_mut(), is_unset()); msg.set_optional_string(""); assert_that!(*msg.optional_string().as_bytes(), empty()); assert_that!(msg.optional_string_opt(), eq(Optional::Set("".into()))); - - msg.optional_string_mut().clear(); - msg.optional_string_mut().or_default(); - assert_that!(*msg.optional_string().as_bytes(), empty()); - assert_that!(msg.optional_string_opt(), eq(Optional::Set("".into()))); } #[test] @@ -198,15 +129,12 @@ fn test_nested_enum_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Zero)); - assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Zero)); msg.set_optional_nested_enum(NestedEnum::Baz); - assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Baz)); assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Baz)); msg.set_optional_nested_enum(NestedEnum::default()); assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Zero)); - assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Zero)); } #[test] @@ -216,29 +144,14 @@ fn test_optional_nested_enum_accessors() { let mut msg = TestProto3Optional::new(); assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Unspecified)); assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Unspecified))); - assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Unspecified)); msg.set_optional_nested_enum(NestedEnum::Baz); - assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Baz)); assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Set(NestedEnum::Baz))); assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Baz)); msg.set_optional_nested_enum(NestedEnum::default()); assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Unspecified)); assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Set(NestedEnum::Unspecified))); - assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Unspecified)); - - msg.optional_nested_enum_mut().clear(); - assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Unspecified)); - assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Unspecified))); - assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Unspecified)); - - let mut field_mut = msg.optional_nested_enum_mut().or_default(); - assert_that!(field_mut.get(), eq(NestedEnum::Unspecified)); - field_mut.set(NestedEnum::Bar); - assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Bar)); - assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Set(NestedEnum::Bar))); - assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Bar)); } #[test] @@ -247,15 +160,12 @@ fn test_foreign_enum_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignZero)); - assert_that!(msg.optional_foreign_enum_mut().get(), eq(ForeignEnum::ForeignZero)); msg.set_optional_foreign_enum(ForeignEnum::ForeignBaz); - assert_that!(msg.optional_foreign_enum_mut().get(), eq(ForeignEnum::ForeignBaz)); assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignBaz)); msg.set_optional_foreign_enum(ForeignEnum::default()); assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignZero)); - assert_that!(msg.optional_foreign_enum_mut().get(), eq(ForeignEnum::ForeignZero)); } #[test] @@ -283,7 +193,7 @@ fn test_oneof_accessors() { assert_that!(msg.oneof_uint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.oneof_field(), matches_pattern!(OneofBytes(eq(b"123")))); - msg.oneof_bytes_mut().clear(); + msg.clear_oneof_bytes(); assert_that!(msg.oneof_field(), matches_pattern!(not_set(_))); } diff --git a/rust/test/shared/accessors_repeated_test.rs b/rust/test/shared/accessors_repeated_test.rs index 132513cf50..8a242dafe8 100644 --- a/rust/test/shared/accessors_repeated_test.rs +++ b/rust/test/shared/accessors_repeated_test.rs @@ -193,7 +193,7 @@ fn test_repeated_message() { let mut msg = TestAllTypes::new(); assert_that!(msg.repeated_nested_message().len(), eq(0)); let mut nested = NestedMessage::new(); - nested.bb_mut().set(1); + nested.set_bb(1); msg.repeated_nested_message_mut().push(nested.as_view()); assert_that!(msg.repeated_nested_message().get(0).unwrap().bb(), eq(1)); @@ -202,7 +202,7 @@ fn test_repeated_message() { assert_that!(msg2.repeated_nested_message().get(0).unwrap().bb(), eq(1)); let mut nested2 = NestedMessage::new(); - nested2.bb_mut().set(2); + nested2.set_bb(2); // TODO: b/320936046 - Test SettableValue once available msg.repeated_nested_message_mut().set(0, nested2.as_view()); diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index 5970d05453..85c9222e42 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -8,7 +8,6 @@ //! Tests covering accessors for singular bool, int32, int64, and bytes fields. use googletest::prelude::*; -use matchers::{is_set, is_unset}; use protobuf::{MutProxy, Optional}; use unittest_proto::{TestAllTypes, TestAllTypes_}; @@ -43,14 +42,6 @@ fn test_optional_fixed32_accessors() { assert_that!(msg.optional_fixed32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_fixed32(), eq(0)); - msg.optional_fixed32_mut().set(99); - assert_that!(msg.optional_fixed32_opt(), eq(Optional::Set(99))); - assert_that!(msg.optional_fixed32(), eq(99)); - - msg.optional_fixed32_mut().clear(); - assert_that!(msg.optional_fixed32_opt(), eq(Optional::Unset(0))); - assert_that!(msg.optional_fixed32(), eq(0)); - msg.set_optional_fixed32(7); assert_that!(msg.optional_fixed32_opt(), eq(Optional::Set(7))); assert_that!(msg.optional_fixed32(), eq(7)); @@ -64,33 +55,15 @@ fn test_optional_fixed32_accessors() { fn test_default_fixed32_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_fixed32(), eq(47)); - assert_that!(msg.default_fixed32_mut().get(), eq(47)); - assert_that!(msg.default_fixed32_mut().is_set(), eq(false)); assert_that!(msg.default_fixed32_opt(), eq(Optional::Unset(47))); msg.set_default_fixed32(7); assert_that!(msg.default_fixed32(), eq(7)); - assert_that!(msg.default_fixed32_mut().get(), eq(7)); - assert_that!(msg.default_fixed32_mut().is_set(), eq(true)); assert_that!(msg.default_fixed32_opt(), eq(Optional::Set(7))); - msg.default_fixed32_mut().set(999); - assert_that!(msg.default_fixed32(), eq(999)); - assert_that!(msg.default_fixed32_mut().get(), eq(999)); - assert_that!(msg.default_fixed32_mut().is_set(), eq(true)); - assert_that!(msg.default_fixed32_opt(), eq(Optional::Set(999))); - - msg.default_fixed32_mut().clear(); + msg.clear_default_fixed32(); assert_that!(msg.default_fixed32(), eq(47)); - assert_that!(msg.default_fixed32_mut().get(), eq(47)); - assert_that!(msg.default_fixed32_mut().is_set(), eq(false)); assert_that!(msg.default_fixed32_opt(), eq(Optional::Unset(47))); - - msg.default_fixed32_mut().or_default(); - assert_that!(msg.default_fixed32(), eq(47)); - assert_that!(msg.default_fixed32_mut().get(), eq(47)); - assert_that!(msg.default_fixed32_mut().is_set(), eq(true)); - assert_that!(msg.default_fixed32_opt(), eq(Optional::Set(47))); } #[test] @@ -103,11 +76,11 @@ fn test_optional_fixed64_accessors() { assert_that!(msg.optional_fixed64_opt(), eq(Optional::Set(99))); assert_that!(msg.optional_fixed64(), eq(99)); - msg.optional_fixed64_mut().set(2000); + msg.set_optional_fixed64(2000); assert_that!(msg.optional_fixed64_opt(), eq(Optional::Set(2000))); assert_that!(msg.optional_fixed64(), eq(2000)); - msg.optional_fixed64_mut().clear(); + msg.clear_optional_fixed64(); assert_that!(msg.optional_fixed64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_fixed64(), eq(0)); } @@ -116,33 +89,19 @@ fn test_optional_fixed64_accessors() { fn test_default_fixed64_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_fixed64(), eq(48)); - assert_that!(msg.default_fixed64_mut().get(), eq(48)); - assert_that!(msg.default_fixed64_mut().is_set(), eq(false)); assert_that!(msg.default_fixed64_opt(), eq(Optional::Unset(48))); msg.set_default_fixed64(4); assert_that!(msg.default_fixed64(), eq(4)); - assert_that!(msg.default_fixed64_mut().get(), eq(4)); - assert_that!(msg.default_fixed64_mut().is_set(), eq(true)); assert_that!(msg.default_fixed64_opt(), eq(Optional::Set(4))); - msg.default_fixed64_mut().set(999); + msg.set_default_fixed64(999); assert_that!(msg.default_fixed64(), eq(999)); - assert_that!(msg.default_fixed64_mut().get(), eq(999)); - assert_that!(msg.default_fixed64_mut().is_set(), eq(true)); assert_that!(msg.default_fixed64_opt(), eq(Optional::Set(999))); - msg.default_fixed64_mut().clear(); + msg.clear_default_fixed64(); assert_that!(msg.default_fixed64(), eq(48)); - assert_that!(msg.default_fixed64_mut().get(), eq(48)); - assert_that!(msg.default_fixed64_mut().is_set(), eq(false)); assert_that!(msg.default_fixed64_opt(), eq(Optional::Unset(48))); - - msg.default_fixed64_mut().or_default(); - assert_that!(msg.default_fixed64(), eq(48)); - assert_that!(msg.default_fixed64_mut().get(), eq(48)); - assert_that!(msg.default_fixed64_mut().is_set(), eq(true)); - assert_that!(msg.default_fixed64_opt(), eq(Optional::Set(48))); } #[test] @@ -155,11 +114,11 @@ fn test_optional_int32_accessors() { assert_that!(msg.optional_int32_opt(), eq(Optional::Set(0))); assert_that!(msg.optional_int32(), eq(0)); - msg.optional_int32_mut().set(1); + msg.set_optional_int32(1); assert_that!(msg.optional_int32_opt(), eq(Optional::Set(1))); assert_that!(msg.optional_int32(), eq(1)); - msg.optional_int32_mut().clear(); + msg.clear_optional_int32(); assert_that!(msg.optional_int32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_int32(), eq(0)); } @@ -168,39 +127,23 @@ fn test_optional_int32_accessors() { fn test_default_int32_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_int32(), eq(41)); - assert_that!(msg.default_int32_mut().get(), eq(41)); - assert_that!(msg.default_int32_mut().is_set(), eq(false)); assert_that!(msg.default_int32_opt(), eq(Optional::Unset(41))); msg.set_default_int32(41); assert_that!(msg.default_int32(), eq(41)); - assert_that!(msg.default_int32_mut().get(), eq(41)); - assert_that!(msg.default_int32_mut().is_set(), eq(true)); assert_that!(msg.default_int32_opt(), eq(Optional::Set(41))); msg.clear_default_int32(); assert_that!(msg.default_int32(), eq(41)); - assert_that!(msg.default_int32_mut().get(), eq(41)); - assert_that!(msg.default_int32_mut().is_set(), eq(false)); assert_that!(msg.default_int32_opt(), eq(Optional::Unset(41))); - msg.default_int32_mut().set(999); + msg.set_default_int32(999); assert_that!(msg.default_int32(), eq(999)); - assert_that!(msg.default_int32_mut().get(), eq(999)); - assert_that!(msg.default_int32_mut().is_set(), eq(true)); assert_that!(msg.default_int32_opt(), eq(Optional::Set(999))); - msg.default_int32_mut().clear(); + msg.clear_default_int32(); assert_that!(msg.default_int32(), eq(41)); - assert_that!(msg.default_int32_mut().get(), eq(41)); - assert_that!(msg.default_int32_mut().is_set(), eq(false)); assert_that!(msg.default_int32_opt(), eq(Optional::Unset(41))); - - msg.default_int32_mut().or_default(); - assert_that!(msg.default_int32(), eq(41)); - assert_that!(msg.default_int32_mut().get(), eq(41)); - assert_that!(msg.default_int32_mut().is_set(), eq(true)); - assert_that!(msg.default_int32_opt(), eq(Optional::Set(41))); } #[test] @@ -209,11 +152,11 @@ fn test_optional_int64_accessors() { assert_that!(msg.optional_int64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_int64(), eq(0)); - msg.optional_int64_mut().set(42); + msg.set_optional_int64(42); assert_that!(msg.optional_int64_opt(), eq(Optional::Set(42))); assert_that!(msg.optional_int64(), eq(42)); - msg.optional_int64_mut().clear(); + msg.clear_optional_int64(); assert_that!(msg.optional_int64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_int64(), eq(0)); } @@ -222,27 +165,15 @@ fn test_optional_int64_accessors() { fn test_default_int64_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_int64(), eq(42)); - assert_that!(msg.default_int64_mut().get(), eq(42)); - assert_that!(msg.default_int64_mut().is_set(), eq(false)); assert_that!(msg.default_int64_opt(), eq(Optional::Unset(42))); - msg.default_int64_mut().set(999); + msg.set_default_int64(999); assert_that!(msg.default_int64(), eq(999)); - assert_that!(msg.default_int64_mut().get(), eq(999)); - assert_that!(msg.default_int64_mut().is_set(), eq(true)); assert_that!(msg.default_int64_opt(), eq(Optional::Set(999))); - msg.default_int64_mut().clear(); + msg.clear_default_int64(); assert_that!(msg.default_int64(), eq(42)); - assert_that!(msg.default_int64_mut().get(), eq(42)); - assert_that!(msg.default_int64_mut().is_set(), eq(false)); assert_that!(msg.default_int64_opt(), eq(Optional::Unset(42))); - - msg.default_int64_mut().or_default(); - assert_that!(msg.default_int64(), eq(42)); - assert_that!(msg.default_int64_mut().get(), eq(42)); - assert_that!(msg.default_int64_mut().is_set(), eq(true)); - assert_that!(msg.default_int64_opt(), eq(Optional::Set(42))); } #[test] @@ -251,11 +182,11 @@ fn test_optional_sint32_accessors() { assert_that!(msg.optional_sint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_sint32(), eq(0)); - msg.optional_sint32_mut().set(-22); + msg.set_optional_sint32(-22); assert_that!(msg.optional_sint32_opt(), eq(Optional::Set(-22))); assert_that!(msg.optional_sint32(), eq(-22)); - msg.optional_sint32_mut().clear(); + msg.clear_optional_sint32(); assert_that!(msg.optional_sint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_sint32(), eq(0)); } @@ -264,27 +195,15 @@ fn test_optional_sint32_accessors() { fn test_default_sint32_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_sint32(), eq(-45)); - assert_that!(msg.default_sint32_mut().get(), eq(-45)); - assert_that!(msg.default_sint32_mut().is_set(), eq(false)); assert_that!(msg.default_sint32_opt(), eq(Optional::Unset(-45))); - msg.default_sint32_mut().set(999); + msg.set_default_sint32(999); assert_that!(msg.default_sint32(), eq(999)); - assert_that!(msg.default_sint32_mut().get(), eq(999)); - assert_that!(msg.default_sint32_mut().is_set(), eq(true)); assert_that!(msg.default_sint32_opt(), eq(Optional::Set(999))); - msg.default_sint32_mut().clear(); + msg.clear_default_sint32(); assert_that!(msg.default_sint32(), eq(-45)); - assert_that!(msg.default_sint32_mut().get(), eq(-45)); - assert_that!(msg.default_sint32_mut().is_set(), eq(false)); assert_that!(msg.default_sint32_opt(), eq(Optional::Unset(-45))); - - msg.default_sint32_mut().or_default(); - assert_that!(msg.default_sint32(), eq(-45)); - assert_that!(msg.default_sint32_mut().get(), eq(-45)); - assert_that!(msg.default_sint32_mut().is_set(), eq(true)); - assert_that!(msg.default_sint32_opt(), eq(Optional::Set(-45))); } #[test] @@ -293,11 +212,11 @@ fn test_optional_sint64_accessors() { assert_that!(msg.optional_sint64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_sint64(), eq(0)); - msg.optional_sint64_mut().set(7000); + msg.set_optional_sint64(7000); assert_that!(msg.optional_sint64_opt(), eq(Optional::Set(7000))); assert_that!(msg.optional_sint64(), eq(7000)); - msg.optional_sint64_mut().clear(); + msg.clear_optional_sint64(); assert_that!(msg.optional_sint64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_sint64(), eq(0)); } @@ -306,27 +225,15 @@ fn test_optional_sint64_accessors() { fn test_default_sint64_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_sint64(), eq(46)); - assert_that!(msg.default_sint64_mut().get(), eq(46)); - assert_that!(msg.default_sint64_mut().is_set(), eq(false)); assert_that!(msg.default_sint64_opt(), eq(Optional::Unset(46))); - msg.default_sint64_mut().set(999); + msg.set_default_sint64(999); assert_that!(msg.default_sint64(), eq(999)); - assert_that!(msg.default_sint64_mut().get(), eq(999)); - assert_that!(msg.default_sint64_mut().is_set(), eq(true)); assert_that!(msg.default_sint64_opt(), eq(Optional::Set(999))); - msg.default_sint64_mut().clear(); + msg.clear_default_sint64(); assert_that!(msg.default_sint64(), eq(46)); - assert_that!(msg.default_sint64_mut().get(), eq(46)); - assert_that!(msg.default_sint64_mut().is_set(), eq(false)); assert_that!(msg.default_sint64_opt(), eq(Optional::Unset(46))); - - msg.default_sint64_mut().or_default(); - assert_that!(msg.default_sint64(), eq(46)); - assert_that!(msg.default_sint64_mut().get(), eq(46)); - assert_that!(msg.default_sint64_mut().is_set(), eq(true)); - assert_that!(msg.default_sint64_opt(), eq(Optional::Set(46))); } #[test] @@ -335,11 +242,11 @@ fn test_optional_uint32_accessors() { assert_that!(msg.optional_uint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_uint32(), eq(0)); - msg.optional_uint32_mut().set(9001); + msg.set_optional_uint32(9001); assert_that!(msg.optional_uint32_opt(), eq(Optional::Set(9001))); assert_that!(msg.optional_uint32(), eq(9001)); - msg.optional_uint32_mut().clear(); + msg.clear_optional_uint32(); assert_that!(msg.optional_uint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_uint32(), eq(0)); } @@ -348,27 +255,15 @@ fn test_optional_uint32_accessors() { fn test_default_uint32_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_uint32(), eq(43)); - assert_that!(msg.default_uint32_mut().get(), eq(43)); - assert_that!(msg.default_uint32_mut().is_set(), eq(false)); assert_that!(msg.default_uint32_opt(), eq(Optional::Unset(43))); - msg.default_uint32_mut().set(999); + msg.set_default_uint32(999); assert_that!(msg.default_uint32(), eq(999)); - assert_that!(msg.default_uint32_mut().get(), eq(999)); - assert_that!(msg.default_uint32_mut().is_set(), eq(true)); assert_that!(msg.default_uint32_opt(), eq(Optional::Set(999))); - msg.default_uint32_mut().clear(); + msg.clear_default_uint32(); assert_that!(msg.default_uint32(), eq(43)); - assert_that!(msg.default_uint32_mut().get(), eq(43)); - assert_that!(msg.default_uint32_mut().is_set(), eq(false)); assert_that!(msg.default_uint32_opt(), eq(Optional::Unset(43))); - - msg.default_uint32_mut().or_default(); - assert_that!(msg.default_uint32(), eq(43)); - assert_that!(msg.default_uint32_mut().get(), eq(43)); - assert_that!(msg.default_uint32_mut().is_set(), eq(true)); - assert_that!(msg.default_uint32_opt(), eq(Optional::Set(43))); } #[test] @@ -377,11 +272,11 @@ fn test_optional_uint64_accessors() { assert_that!(msg.optional_uint64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_uint64(), eq(0)); - msg.optional_uint64_mut().set(42); + msg.set_optional_uint64(42); assert_that!(msg.optional_uint64_opt(), eq(Optional::Set(42))); assert_that!(msg.optional_uint64(), eq(42)); - msg.optional_uint64_mut().clear(); + msg.clear_optional_uint64(); assert_that!(msg.optional_uint64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_uint64(), eq(0)); } @@ -390,27 +285,15 @@ fn test_optional_uint64_accessors() { fn test_default_uint64_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_uint64(), eq(44)); - assert_that!(msg.default_uint64_mut().get(), eq(44)); - assert_that!(msg.default_uint64_mut().is_set(), eq(false)); assert_that!(msg.default_uint64_opt(), eq(Optional::Unset(44))); - msg.default_uint64_mut().set(999); + msg.set_default_uint64(999); assert_that!(msg.default_uint64(), eq(999)); - assert_that!(msg.default_uint64_mut().get(), eq(999)); - assert_that!(msg.default_uint64_mut().is_set(), eq(true)); assert_that!(msg.default_uint64_opt(), eq(Optional::Set(999))); - msg.default_uint64_mut().clear(); + msg.clear_default_uint64(); assert_that!(msg.default_uint64(), eq(44)); - assert_that!(msg.default_uint64_mut().get(), eq(44)); - assert_that!(msg.default_uint64_mut().is_set(), eq(false)); assert_that!(msg.default_uint64_opt(), eq(Optional::Unset(44))); - - msg.default_uint64_mut().or_default(); - assert_that!(msg.default_uint64(), eq(44)); - assert_that!(msg.default_uint64_mut().get(), eq(44)); - assert_that!(msg.default_uint64_mut().is_set(), eq(true)); - assert_that!(msg.default_uint64_opt(), eq(Optional::Set(44))); } #[test] @@ -419,11 +302,11 @@ fn test_optional_float_accessors() { assert_that!(msg.optional_float_opt(), eq(Optional::Unset(0.0))); assert_that!(msg.optional_float(), eq(0.0)); - msg.optional_float_mut().set(std::f32::consts::PI); + msg.set_optional_float(std::f32::consts::PI); assert_that!(msg.optional_float_opt(), eq(Optional::Set(std::f32::consts::PI))); assert_that!(msg.optional_float(), eq(std::f32::consts::PI)); - msg.optional_float_mut().clear(); + msg.clear_optional_float(); assert_that!(msg.optional_float_opt(), eq(Optional::Unset(0.0))); assert_that!(msg.optional_float(), eq(0.0)); } @@ -432,27 +315,15 @@ fn test_optional_float_accessors() { fn test_default_float_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_float(), eq(51.5)); - assert_that!(msg.default_float_mut().get(), eq(51.5)); - assert_that!(msg.default_float_mut().is_set(), eq(false)); assert_that!(msg.default_float_opt(), eq(Optional::Unset(51.5))); - msg.default_float_mut().set(999.9); + msg.set_default_float(999.9); assert_that!(msg.default_float(), eq(999.9)); - assert_that!(msg.default_float_mut().get(), eq(999.9)); - assert_that!(msg.default_float_mut().is_set(), eq(true)); assert_that!(msg.default_float_opt(), eq(Optional::Set(999.9))); - msg.default_float_mut().clear(); + msg.clear_default_float(); assert_that!(msg.default_float(), eq(51.5)); - assert_that!(msg.default_float_mut().get(), eq(51.5)); - assert_that!(msg.default_float_mut().is_set(), eq(false)); assert_that!(msg.default_float_opt(), eq(Optional::Unset(51.5))); - - msg.default_float_mut().or_default(); - assert_that!(msg.default_float(), eq(51.5)); - assert_that!(msg.default_float_mut().get(), eq(51.5)); - assert_that!(msg.default_float_mut().is_set(), eq(true)); - assert_that!(msg.default_float_opt(), eq(Optional::Set(51.5))); } #[test] @@ -461,11 +332,11 @@ fn test_optional_double_accessors() { assert_that!(msg.optional_double_opt(), eq(Optional::Unset(0.0))); assert_that!(msg.optional_double(), eq(0.0)); - msg.optional_double_mut().set(-10.99); + msg.set_optional_double(-10.99); assert_that!(msg.optional_double_opt(), eq(Optional::Set(-10.99))); assert_that!(msg.optional_double(), eq(-10.99)); - msg.optional_double_mut().clear(); + msg.clear_optional_double(); assert_that!(msg.optional_double_opt(), eq(Optional::Unset(0.0))); assert_that!(msg.optional_double(), eq(0.0)); } @@ -474,27 +345,15 @@ fn test_optional_double_accessors() { fn test_default_double_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_double(), eq(52e3)); - assert_that!(msg.default_double_mut().get(), eq(52e3)); - assert_that!(msg.default_double_mut().is_set(), eq(false)); assert_that!(msg.default_double_opt(), eq(Optional::Unset(52e3))); - msg.default_double_mut().set(999.9); + msg.set_default_double(999.9); assert_that!(msg.default_double(), eq(999.9)); - assert_that!(msg.default_double_mut().get(), eq(999.9)); - assert_that!(msg.default_double_mut().is_set(), eq(true)); assert_that!(msg.default_double_opt(), eq(Optional::Set(999.9))); - msg.default_double_mut().clear(); + msg.clear_default_double(); assert_that!(msg.default_double(), eq(52e3)); - assert_that!(msg.default_double_mut().get(), eq(52e3)); - assert_that!(msg.default_double_mut().is_set(), eq(false)); assert_that!(msg.default_double_opt(), eq(Optional::Unset(52e3))); - - msg.default_double_mut().or_default(); - assert_that!(msg.default_double(), eq(52e3)); - assert_that!(msg.default_double_mut().get(), eq(52e3)); - assert_that!(msg.default_double_mut().is_set(), eq(true)); - assert_that!(msg.default_double_opt(), eq(Optional::Set(52e3))); } #[test] @@ -502,10 +361,10 @@ fn test_optional_bool_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.optional_bool_opt(), eq(Optional::Unset(false))); - msg.optional_bool_mut().set(true); + msg.set_optional_bool(true); assert_that!(msg.optional_bool_opt(), eq(Optional::Set(true))); - msg.optional_bool_mut().clear(); + msg.clear_optional_bool(); assert_that!(msg.optional_bool_opt(), eq(Optional::Unset(false))); } @@ -513,27 +372,15 @@ fn test_optional_bool_accessors() { fn test_default_bool_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_bool(), eq(true)); - assert_that!(msg.default_bool_mut().get(), eq(true)); - assert_that!(msg.default_bool_mut().is_set(), eq(false)); assert_that!(msg.default_bool_opt(), eq(Optional::Unset(true))); - msg.default_bool_mut().set(false); + msg.set_default_bool(false); assert_that!(msg.default_bool(), eq(false)); - assert_that!(msg.default_bool_mut().get(), eq(false)); - assert_that!(msg.default_bool_mut().is_set(), eq(true)); assert_that!(msg.default_bool_opt(), eq(Optional::Set(false))); - msg.default_bool_mut().clear(); + msg.clear_default_bool(); assert_that!(msg.default_bool(), eq(true)); - assert_that!(msg.default_bool_mut().get(), eq(true)); - assert_that!(msg.default_bool_mut().is_set(), eq(false)); assert_that!(msg.default_bool_opt(), eq(Optional::Unset(true))); - - msg.default_bool_mut().or_default(); - assert_that!(msg.default_bool(), eq(true)); - assert_that!(msg.default_bool_mut().get(), eq(true)); - assert_that!(msg.default_bool_mut().is_set(), eq(true)); - assert_that!(msg.default_bool_opt(), eq(Optional::Set(true))); } #[test] @@ -541,45 +388,21 @@ fn test_optional_bytes_accessors() { let mut msg = TestAllTypes::new(); assert_that!(*msg.optional_bytes(), empty()); assert_that!(msg.optional_bytes_opt(), eq(Optional::Unset(&b""[..]))); - assert_that!(*msg.optional_bytes_mut().get(), empty()); - assert_that!(msg.optional_bytes_mut(), is_unset()); { let s = Vec::from(&b"hello world"[..]); - msg.optional_bytes_mut().set(&s[..]); + msg.set_optional_bytes(&s[..]); } assert_that!(msg.optional_bytes(), eq(b"hello world")); assert_that!(msg.optional_bytes_opt(), eq(Optional::Set(&b"hello world"[..]))); - assert_that!(msg.optional_bytes_mut(), is_set()); - assert_that!(msg.optional_bytes_mut().get(), eq(b"hello world")); - - msg.optional_bytes_mut().or_default().set(b"accessors_test"); - assert_that!(msg.optional_bytes(), eq(b"accessors_test")); - assert_that!(msg.optional_bytes_opt(), eq(Optional::Set(&b"accessors_test"[..]))); - assert_that!(msg.optional_bytes_mut(), is_set()); - assert_that!(msg.optional_bytes_mut().get(), eq(b"accessors_test")); - assert_that!(msg.optional_bytes_mut().or_default().get(), eq(b"accessors_test")); - msg.optional_bytes_mut().clear(); + msg.clear_optional_bytes(); assert_that!(*msg.optional_bytes(), empty()); assert_that!(msg.optional_bytes_opt(), eq(Optional::Unset(&b""[..]))); - assert_that!(msg.optional_bytes_mut(), is_unset()); - - msg.optional_bytes_mut().set(b""); - assert_that!(*msg.optional_bytes(), empty()); - assert_that!(msg.optional_bytes_opt(), eq(Optional::Set(&b""[..]))); - msg.optional_bytes_mut().clear(); - msg.optional_bytes_mut().or_default(); + msg.set_optional_bytes(b""); assert_that!(*msg.optional_bytes(), empty()); assert_that!(msg.optional_bytes_opt(), eq(Optional::Set(&b""[..]))); - - msg.optional_bytes_mut().or_default().set(b"\xffbinary\x85non-utf8"); - assert_that!(msg.optional_bytes(), eq(b"\xffbinary\x85non-utf8")); - assert_that!(msg.optional_bytes_opt(), eq(Optional::Set(&b"\xffbinary\x85non-utf8"[..]))); - assert_that!(msg.optional_bytes_mut(), is_set()); - assert_that!(msg.optional_bytes_mut().get(), eq(b"\xffbinary\x85non-utf8")); - assert_that!(msg.optional_bytes_mut().or_default().get(), eq(b"\xffbinary\x85non-utf8")); } #[test] @@ -587,49 +410,25 @@ fn test_nonempty_default_bytes_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_bytes(), eq(b"world")); assert_that!(msg.default_bytes_opt(), eq(Optional::Unset(&b"world"[..]))); - assert_that!(msg.default_bytes_mut().get(), eq(b"world")); - assert_that!(msg.default_bytes_mut(), is_unset()); { let s = String::from("hello world"); - msg.default_bytes_mut().set(s.as_bytes()); + msg.set_default_bytes(s.as_bytes()); } assert_that!(msg.default_bytes(), eq(b"hello world")); assert_that!(msg.default_bytes_opt(), eq(Optional::Set(&b"hello world"[..]))); - assert_that!(msg.default_bytes_mut(), is_set()); - assert_that!(msg.default_bytes_mut().get(), eq(b"hello world")); - - msg.default_bytes_mut().or_default().set(b"accessors_test"); - assert_that!(msg.default_bytes(), eq(b"accessors_test")); - assert_that!(msg.default_bytes_opt(), eq(Optional::Set(&b"accessors_test"[..]))); - assert_that!(msg.default_bytes_mut(), is_set()); - assert_that!(msg.default_bytes_mut().get(), eq(b"accessors_test")); - assert_that!(msg.default_bytes_mut().or_default().get(), eq(b"accessors_test")); - msg.default_bytes_mut().clear(); + msg.clear_default_bytes(); assert_that!(msg.default_bytes(), eq(b"world")); assert_that!(msg.default_bytes_opt(), eq(Optional::Unset(&b"world"[..]))); - assert_that!(msg.default_bytes_mut(), is_unset()); msg.set_default_bytes(b""); assert_that!(*msg.default_bytes(), empty()); assert_that!(msg.default_bytes_opt(), eq(Optional::Set(&b""[..]))); - msg.default_bytes_mut().clear(); - msg.default_bytes_mut().or_default(); - assert_that!(msg.default_bytes(), eq(b"world")); - assert_that!(msg.default_bytes_opt(), eq(Optional::Set(&b"world"[..]))); - msg.clear_default_bytes(); + assert_that!(msg.default_bytes(), eq(b"world")); assert_that!(msg.default_bytes_opt(), eq(Optional::Unset(&b"world"[..]))); - assert_that!(msg.default_bytes_mut(), is_unset()); - - msg.default_bytes_mut().or_default().set(b"\xffbinary\x85non-utf8"); - assert_that!(msg.default_bytes(), eq(b"\xffbinary\x85non-utf8")); - assert_that!(msg.default_bytes_opt(), eq(Optional::Set(&b"\xffbinary\x85non-utf8"[..]))); - assert_that!(msg.default_bytes_mut(), is_set()); - assert_that!(msg.default_bytes_mut().get(), eq(b"\xffbinary\x85non-utf8")); - assert_that!(msg.default_bytes_mut().or_default().get(), eq(b"\xffbinary\x85non-utf8")); } #[test] @@ -637,38 +436,25 @@ fn test_optional_string_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.optional_string(), eq("")); assert_that!(msg.optional_string_opt(), eq(Optional::Unset("".into()))); - assert_that!(msg.optional_string_mut().get(), eq("")); - assert_that!(msg.optional_string_mut(), is_unset()); { let s = String::from("hello world"); - msg.optional_string_mut().set(&s[..]); + msg.set_optional_string(&s[..]); } assert_that!(msg.optional_string(), eq("hello world")); assert_that!(msg.optional_string_opt(), eq(Optional::Set("hello world".into()))); - assert_that!(msg.optional_string_mut(), is_set()); - assert_that!(msg.optional_string_mut().get(), eq("hello world")); - msg.optional_string_mut().or_default().set("accessors_test"); - assert_that!(msg.optional_string(), eq("accessors_test")); - assert_that!(msg.optional_string_opt(), eq(Optional::Set("accessors_test".into()))); - assert_that!(msg.optional_string_mut(), is_set()); - assert_that!(msg.optional_string_mut().get(), eq("accessors_test")); - assert_that!(msg.optional_string_mut().or_default().get(), eq("accessors_test")); - - msg.optional_string_mut().clear(); + msg.clear_optional_string(); assert_that!(msg.optional_string(), eq("")); assert_that!(msg.optional_string_opt(), eq(Optional::Unset("".into()))); - assert_that!(msg.optional_string_mut(), is_unset()); msg.set_optional_string(""); assert_that!(msg.optional_string(), eq("")); assert_that!(msg.optional_string_opt(), eq(Optional::Set("".into()))); msg.clear_optional_string(); - msg.optional_string_mut().or_default(); assert_that!(msg.optional_string(), eq("")); - assert_that!(msg.optional_string_opt(), eq(Optional::Set("".into()))); + assert_that!(msg.optional_string_opt(), eq(Optional::Unset("".into()))); } #[test] @@ -676,38 +462,25 @@ fn test_nonempty_default_string_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_string(), eq("hello")); assert_that!(msg.default_string_opt(), eq(Optional::Unset("hello".into()))); - assert_that!(msg.default_string_mut().get(), eq("hello")); - assert_that!(msg.default_string_mut(), is_unset()); { let s = String::from("hello world"); - msg.default_string_mut().set(&s[..]); + msg.set_default_string(&s[..]); } assert_that!(msg.default_string(), eq("hello world")); assert_that!(msg.default_string_opt(), eq(Optional::Set("hello world".into()))); - assert_that!(msg.default_string_mut(), is_set()); - assert_that!(msg.default_string_mut().get(), eq("hello world")); - - msg.default_string_mut().or_default().set("accessors_test"); - assert_that!(msg.default_string(), eq("accessors_test")); - assert_that!(msg.default_string_opt(), eq(Optional::Set("accessors_test".into()))); - assert_that!(msg.default_string_mut(), is_set()); - assert_that!(msg.default_string_mut().get(), eq("accessors_test")); - assert_that!(msg.default_string_mut().or_default().get(), eq("accessors_test")); - msg.default_string_mut().clear(); + msg.clear_default_string(); assert_that!(msg.default_string(), eq("hello")); assert_that!(msg.default_string_opt(), eq(Optional::Unset("hello".into()))); - assert_that!(msg.default_string_mut(), is_unset()); - msg.default_string_mut().set(""); + msg.set_default_string(""); assert_that!(msg.default_string(), eq("")); assert_that!(msg.default_string_opt(), eq(Optional::Set("".into()))); - msg.default_string_mut().clear(); - msg.default_string_mut().or_default(); + msg.clear_default_string(); assert_that!(msg.default_string(), eq("hello")); - assert_that!(msg.default_string_opt(), eq(Optional::Set("hello".into()))); + assert_that!(msg.default_string_opt(), eq(Optional::Unset("hello".into()))); } #[test] @@ -725,7 +498,7 @@ fn test_singular_msg_field() { // Test setting an owned NestedMessage onto another message. let mut new_nested = NestedMessage::new(); - new_nested.bb_mut().set(7); + new_nested.set_bb(7); nested_msg_mut.set(new_nested); assert_that!(nested_msg_mut.bb(), eq(7)); } @@ -747,10 +520,10 @@ fn test_message_opt_set() { let submsg = TestAllTypes_::NestedMessage::new(); assert_that!(msg.optional_nested_message_opt().is_set(), eq(false)); - msg.optional_nested_message_mut().set(submsg); + msg.set_optional_nested_message(submsg); assert_that!(msg.optional_nested_message_opt().is_set(), eq(true)); - msg.optional_nested_message_mut().clear(); + msg.clear_optional_nested_message(); assert_that!(msg.optional_nested_message_mut().is_set(), eq(false)); } @@ -766,7 +539,7 @@ fn test_setting_submsg() { // confirm that invoking .set on a submsg indeed flips the set bit assert_that!(msg.optional_nested_message_mut().is_set(), eq(true)); - msg.optional_nested_message_mut().clear(); + msg.clear_optional_nested_message(); assert_that!(msg.optional_nested_message_mut().is_set(), eq(false)); } @@ -779,7 +552,7 @@ fn test_msg_or_default() { // confirm that that or_default makes the field Present assert_that!(msg.optional_nested_message_mut().is_set(), eq(true)); - msg.optional_nested_message_mut().clear(); + msg.clear_optional_nested_message(); assert_that!(msg.optional_nested_message_mut().is_set(), eq(false)); } @@ -791,11 +564,11 @@ fn test_optional_nested_enum_accessors() { assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Foo))); assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Foo)); - msg.optional_nested_enum_mut().set(NestedEnum::Neg); + msg.set_optional_nested_enum(NestedEnum::Neg); assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Set(NestedEnum::Neg))); assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Neg)); - msg.optional_nested_enum_mut().clear(); + msg.clear_optional_nested_enum(); assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Foo))); assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Foo)); } @@ -806,27 +579,15 @@ fn test_default_nested_enum_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_nested_enum(), eq(NestedEnum::Bar)); - assert_that!(msg.default_nested_enum_mut().get(), eq(NestedEnum::Bar)); - assert_that!(msg.default_nested_enum_mut().is_set(), eq(false)); assert_that!(msg.default_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Bar))); - msg.default_nested_enum_mut().set(NestedEnum::Baz); + msg.set_default_nested_enum(NestedEnum::Baz); assert_that!(msg.default_nested_enum(), eq(NestedEnum::Baz)); - assert_that!(msg.default_nested_enum_mut().get(), eq(NestedEnum::Baz)); - assert_that!(msg.default_nested_enum_mut().is_set(), eq(true)); assert_that!(msg.default_nested_enum_opt(), eq(Optional::Set(NestedEnum::Baz))); - msg.default_nested_enum_mut().clear(); + msg.clear_default_nested_enum(); assert_that!(msg.default_nested_enum(), eq(NestedEnum::Bar)); - assert_that!(msg.default_nested_enum_mut().get(), eq(NestedEnum::Bar)); - assert_that!(msg.default_nested_enum_mut().is_set(), eq(false)); assert_that!(msg.default_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Bar))); - - msg.default_nested_enum_mut().or_default(); - assert_that!(msg.default_nested_enum(), eq(NestedEnum::Bar)); - assert_that!(msg.default_nested_enum_mut().get(), eq(NestedEnum::Bar)); - assert_that!(msg.default_nested_enum_mut().is_set(), eq(true)); - assert_that!(msg.default_nested_enum_opt(), eq(Optional::Set(NestedEnum::Bar))); } #[test] @@ -837,11 +598,11 @@ fn test_optional_foreign_enum_accessors() { assert_that!(msg.optional_foreign_enum_opt(), eq(Optional::Unset(ForeignEnum::ForeignFoo))); assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignFoo)); - msg.optional_foreign_enum_mut().set(ForeignEnum::ForeignBax); + msg.set_optional_foreign_enum(ForeignEnum::ForeignBax); assert_that!(msg.optional_foreign_enum_opt(), eq(Optional::Set(ForeignEnum::ForeignBax))); assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignBax)); - msg.optional_foreign_enum_mut().clear(); + msg.clear_optional_foreign_enum(); assert_that!(msg.optional_foreign_enum_opt(), eq(Optional::Unset(ForeignEnum::ForeignFoo))); assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignFoo)); } @@ -852,27 +613,15 @@ fn test_default_foreign_enum_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_foreign_enum(), eq(ForeignEnum::ForeignBar)); - assert_that!(msg.default_foreign_enum_mut().get(), eq(ForeignEnum::ForeignBar)); - assert_that!(msg.default_foreign_enum_mut().is_set(), eq(false)); assert_that!(msg.default_foreign_enum_opt(), eq(Optional::Unset(ForeignEnum::ForeignBar))); - msg.default_foreign_enum_mut().set(ForeignEnum::ForeignBaz); + msg.set_default_foreign_enum(ForeignEnum::ForeignBaz); assert_that!(msg.default_foreign_enum(), eq(ForeignEnum::ForeignBaz)); - assert_that!(msg.default_foreign_enum_mut().get(), eq(ForeignEnum::ForeignBaz)); - assert_that!(msg.default_foreign_enum_mut().is_set(), eq(true)); assert_that!(msg.default_foreign_enum_opt(), eq(Optional::Set(ForeignEnum::ForeignBaz))); - msg.default_foreign_enum_mut().clear(); + msg.clear_default_foreign_enum(); assert_that!(msg.default_foreign_enum(), eq(ForeignEnum::ForeignBar)); - assert_that!(msg.default_foreign_enum_mut().get(), eq(ForeignEnum::ForeignBar)); - assert_that!(msg.default_foreign_enum_mut().is_set(), eq(false)); assert_that!(msg.default_foreign_enum_opt(), eq(Optional::Unset(ForeignEnum::ForeignBar))); - - msg.default_foreign_enum_mut().or_default(); - assert_that!(msg.default_foreign_enum(), eq(ForeignEnum::ForeignBar)); - assert_that!(msg.default_foreign_enum_mut().get(), eq(ForeignEnum::ForeignBar)); - assert_that!(msg.default_foreign_enum_mut().is_set(), eq(true)); - assert_that!(msg.default_foreign_enum_opt(), eq(Optional::Set(ForeignEnum::ForeignBar))); } #[test] @@ -883,11 +632,11 @@ fn test_optional_import_enum_accessors() { assert_that!(msg.optional_import_enum_opt(), eq(Optional::Unset(ImportEnum::ImportFoo))); assert_that!(msg.optional_import_enum(), eq(ImportEnum::ImportFoo)); - msg.optional_import_enum_mut().set(ImportEnum::ImportBar); + msg.set_optional_import_enum(ImportEnum::ImportBar); assert_that!(msg.optional_import_enum_opt(), eq(Optional::Set(ImportEnum::ImportBar))); assert_that!(msg.optional_import_enum(), eq(ImportEnum::ImportBar)); - msg.optional_import_enum_mut().clear(); + msg.clear_optional_import_enum(); assert_that!(msg.optional_import_enum_opt(), eq(Optional::Unset(ImportEnum::ImportFoo))); assert_that!(msg.optional_import_enum(), eq(ImportEnum::ImportFoo)); } @@ -898,27 +647,15 @@ fn test_default_import_enum_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.default_import_enum(), eq(ImportEnum::ImportBar)); - assert_that!(msg.default_import_enum_mut().get(), eq(ImportEnum::ImportBar)); - assert_that!(msg.default_import_enum_mut().is_set(), eq(false)); assert_that!(msg.default_import_enum_opt(), eq(Optional::Unset(ImportEnum::ImportBar))); - msg.default_import_enum_mut().set(ImportEnum::ImportBaz); + msg.set_default_import_enum(ImportEnum::ImportBaz); assert_that!(msg.default_import_enum(), eq(ImportEnum::ImportBaz)); - assert_that!(msg.default_import_enum_mut().get(), eq(ImportEnum::ImportBaz)); - assert_that!(msg.default_import_enum_mut().is_set(), eq(true)); assert_that!(msg.default_import_enum_opt(), eq(Optional::Set(ImportEnum::ImportBaz))); - msg.default_import_enum_mut().clear(); + msg.clear_default_import_enum(); assert_that!(msg.default_import_enum(), eq(ImportEnum::ImportBar)); - assert_that!(msg.default_import_enum_mut().get(), eq(ImportEnum::ImportBar)); - assert_that!(msg.default_import_enum_mut().is_set(), eq(false)); assert_that!(msg.default_import_enum_opt(), eq(Optional::Unset(ImportEnum::ImportBar))); - - msg.default_import_enum_mut().or_default(); - assert_that!(msg.default_import_enum(), eq(ImportEnum::ImportBar)); - assert_that!(msg.default_import_enum_mut().get(), eq(ImportEnum::ImportBar)); - assert_that!(msg.default_import_enum_mut().is_set(), eq(true)); - assert_that!(msg.default_import_enum_opt(), eq(Optional::Set(ImportEnum::ImportBar))); } #[test] @@ -930,32 +667,32 @@ fn test_oneof_accessors() { assert_that!(msg.foo(), matches_pattern!(not_set(_))); assert_that!(msg.foo_case(), eq(FooCase::not_set)); - msg.foo_int_mut().set(7); + msg.set_foo_int(7); assert_that!(msg.foo_int_opt(), eq(Optional::Set(7))); assert_that!(msg.foo(), matches_pattern!(FooInt(eq(7)))); assert_that!(msg.foo_case(), eq(FooCase::FooInt)); - msg.foo_int_mut().clear(); + msg.clear_foo_int(); assert_that!(msg.foo_int_opt(), eq(Optional::Unset(0))); assert_that!(msg.foo(), matches_pattern!(not_set(_))); assert_that!(msg.foo_case(), eq(FooCase::not_set)); - msg.foo_int_mut().set(7); - msg.foo_bytes_mut().set(b"123"); + msg.set_foo_int(7); + msg.set_foo_bytes(b"123"); assert_that!(msg.foo_int_opt(), eq(Optional::Unset(0))); assert_that!(msg.foo(), matches_pattern!(FooBytes(eq(b"123")))); assert_that!(msg.foo_case(), eq(FooCase::FooBytes)); - msg.foo_enum_mut().set(NestedEnum::Foo); + msg.set_foo_enum(NestedEnum::Foo); assert_that!(msg.foo(), matches_pattern!(FooEnum(eq(NestedEnum::Foo)))); assert_that!(msg.foo_case(), eq(FooCase::FooEnum)); // Test the accessors or $Msg$Mut let mut msg_mut = msg.as_mut(); assert_that!(msg_mut.foo(), matches_pattern!(FooEnum(eq(NestedEnum::Foo)))); - msg_mut.foo_int_mut().set(7); - msg_mut.foo_bytes_mut().set(b"123"); + msg_mut.set_foo_int(7); + msg_mut.set_foo_bytes(b"123"); assert_that!(msg_mut.foo(), matches_pattern!(FooBytes(eq(b"123")))); assert_that!(msg_mut.foo_case(), eq(FooCase::FooBytes)); assert_that!(msg_mut.foo_int_opt(), eq(Optional::Unset(0))); @@ -976,24 +713,24 @@ fn test_msg_oneof_default_accessors() { let mut msg = unittest_proto::TestOneof2::new(); assert_that!(msg.bar(), matches_pattern!(not_set(_))); - msg.bar_int_mut().set(7); + msg.set_bar_int(7); assert_that!(msg.bar_int_opt(), eq(Optional::Set(7))); assert_that!(msg.bar(), matches_pattern!(BarInt(eq(7)))); assert_that!(msg.bar_case(), eq(BarCase::BarInt)); - msg.bar_int_mut().clear(); + msg.clear_bar_int(); assert_that!(msg.bar_int_opt(), eq(Optional::Unset(5))); assert_that!(msg.bar(), matches_pattern!(not_set(_))); assert_that!(msg.bar_case(), eq(BarCase::not_set)); - msg.bar_int_mut().set(7); - msg.bar_bytes_mut().set(b"123"); + msg.set_bar_int(7); + msg.set_bar_bytes(b"123"); assert_that!(msg.bar_int_opt(), eq(Optional::Unset(5))); assert_that!(msg.bar_enum_opt(), eq(Optional::Unset(NestedEnum::Bar))); assert_that!(msg.bar(), matches_pattern!(BarBytes(eq(b"123")))); assert_that!(msg.bar_case(), eq(BarCase::BarBytes)); - msg.bar_enum_mut().set(NestedEnum::Baz); + msg.set_bar_enum(NestedEnum::Baz); assert_that!(msg.bar(), matches_pattern!(BarEnum(eq(NestedEnum::Baz)))); assert_that!(msg.bar_case(), eq(BarCase::BarEnum)); assert_that!(msg.bar_int_opt(), eq(Optional::Unset(5))); @@ -1006,7 +743,7 @@ fn test_set_message_from_view() { use protobuf::MutProxy; let mut m1 = TestAllTypes::new(); - m1.optional_int32_mut().set(1); + m1.set_optional_int32(1); let mut m2 = TestAllTypes::new(); m2.as_mut().set(m1.as_view()); @@ -1021,7 +758,7 @@ fn test_group() { assert_that!(m.optionalgroup_opt().is_set(), eq(false)); assert_that!(m.optionalgroup().a(), eq(0)); - m.optionalgroup_mut().or_default().a_mut().set(7); + m.optionalgroup_mut().or_default().set_a(7); assert_that!(m.optionalgroup_opt().is_set(), eq(true)); assert_that!(m.optionalgroup().a(), eq(7)); } diff --git a/rust/test/shared/edition2023_test.rs b/rust/test/shared/edition2023_test.rs index 35388df237..44f10bee2a 100644 --- a/rust/test/shared/edition2023_test.rs +++ b/rust/test/shared/edition2023_test.rs @@ -13,11 +13,7 @@ use googletest::prelude::*; #[test] fn check_edition2023_works() { - let mut msg = edition2023_proto::EditionsMessage::new(); - - // plain_field supports presence. - assert_that!(msg.plain_field_mut().or_default().get(), eq(0)); - - // implicit presence fields' _mut() skips FieldEntry. - assert_that!(msg.implicit_presence_field_mut().get(), eq(0)); + let msg = edition2023_proto::EditionsMessage::new(); + assert_that!(msg.plain_field_opt().into_inner(), eq(0)); + assert_that!(msg.implicit_presence_field(), eq(0)); } diff --git a/rust/test/shared/simple_nested_test.rs b/rust/test/shared/simple_nested_test.rs index a5dd862557..cebd982b7f 100644 --- a/rust/test/shared/simple_nested_test.rs +++ b/rust/test/shared/simple_nested_test.rs @@ -6,7 +6,6 @@ // https://developers.google.com/open-source/licenses/bsd use googletest::prelude::*; -use nested_proto::Outer_::InnerMut; use nested_proto::Outer_::InnerView; use nested_proto::Outer_::Inner_::InnerEnum; use nested_proto::*; @@ -80,66 +79,6 @@ fn test_nested_view_lifetimes() { assert_that!(string_map.len(), eq(0)); } -#[test] -fn test_nested_muts() { - // Covers the setting of a mut and the following assertion - // confirming the new value. Replacement example: - // old: - // inner_msg.double_mut().set(543.21); - // assert_that!(inner_msg.double_mut().get(), eq(543.21)); - // new: - // set_and_test_mut!(inner_msg => double_mut, 543.21); - macro_rules! set_and_test_mut { - ( $a:expr => $($target_mut:ident, $val:expr;)* ) => { - $( - $a.$target_mut().set($val); - assert_that!($a.$target_mut().get(), eq($val)); - )* - }; - } - - let mut outer_msg = Outer::new(); - let mut inner_msg: InnerMut<'_> = outer_msg.inner_mut().or_default(); - assert_that!( - inner_msg, - matches_pattern!(InnerMut{ - float(): eq(0.0), - double(): eq(0.0), - int32(): eq(0), - int64(): eq(0), - uint32(): eq(0), - uint64(): eq(0), - sint32(): eq(0), - sint64(): eq(0), - fixed32(): eq(0), - fixed64(): eq(0), - sfixed32(): eq(0), - sfixed64(): eq(0), - bool(): eq(false), - inner_enum(): eq(InnerEnum::Unspecified) - }) - ); - assert_that!(inner_msg.string_mut().get(), eq("")); - assert_that!(inner_msg.bytes_mut().get(), eq(b"")); - - set_and_test_mut!(inner_msg => - double_mut, 543.21; - float_mut, 1.23; - int32_mut, 12; - int64_mut, 42; - uint32_mut, 13; - uint64_mut, 5000; - sint32_mut, -2; - sint64_mut, 322; - fixed32_mut, 77; - fixed64_mut, 999; - bool_mut, true; - string_mut, "hi"; - bytes_mut, b"bye"; - inner_enum_mut, InnerEnum::Foo; - ); -} - #[test] fn test_msg_from_outside() { // let's make sure that we're not just working for messages nested inside @@ -169,7 +108,7 @@ fn test_recursive_mut() { let mut three = two.rec_mut().or_default(); let mut four = three.rec_mut().or_default(); - four.num_mut().set(1); + four.set_num(1); assert_that!(four.num(), eq(1)); assert_that!(rec.num(), eq(0)); diff --git a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc index 3d552ed222..86330e1ab7 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc @@ -41,7 +41,6 @@ void SingularScalar::InMsgImpl(Context& ctx, const FieldDescriptor& field, }}, {"getter_opt", [&] { - if (!field.is_optional()) return; if (!field.has_presence()) return; ctx.Emit(R"rs( pub fn $raw_field_name$_opt($view_self$) -> $pb$::Optional<$Scalar$> { @@ -74,83 +73,12 @@ void SingularScalar::InMsgImpl(Context& ctx, const FieldDescriptor& field, {"getter_thunk", ThunkName(ctx, field, "get")}, {"setter_thunk", ThunkName(ctx, field, "set")}, {"clearer_thunk", ThunkName(ctx, field, "clear")}, - {"vtable_name", VTableName(field)}, - {"vtable", - [&] { - if (accessor_case != AccessorCase::OWNED) { - return; - } - if (field.has_presence()) { - ctx.Emit(R"rs( - const $vtable_name$: &'static $pbi$::PrimitiveOptionalMutVTable<$Scalar$> = - &$pbi$::PrimitiveOptionalMutVTable::new( - $pbi$::Private, - $getter_thunk$, - $setter_thunk$, - $clearer_thunk$, - $default_value$, - ); - )rs"); - } else { - ctx.Emit(R"rs( - const $vtable_name$: &'static $pbi$::PrimitiveVTable<$Scalar$> = - &$pbi$::PrimitiveVTable::new( - $pbi$::Private, - $getter_thunk$, - $setter_thunk$, - ); - )rs"); - } - }}, - {"getter_mut", - [&] { - if (accessor_case == AccessorCase::VIEW) { - return; - } - if (field.has_presence()) { - ctx.Emit(R"rs( - pub fn $raw_field_name$_mut(&mut self) -> $pb$::FieldEntry<'_, $Scalar$> { - unsafe { - let has = $hazzer_thunk$(self.raw_msg()); - $pbi$::new_vtable_field_entry::<$Scalar$>( - $pbi$::Private, - self.as_mutator_message_ref(), - $Msg$::$vtable_name$, - has, - ) - } - } - )rs"); - } else { - ctx.Emit(R"rs( - pub fn $raw_field_name$_mut(&mut self) -> $pb$::Mut<'_, $Scalar$> { - // SAFETY: - // - The message is valid for the output lifetime. - // - The vtable is valid for the field. - // - There is no way to mutate the element for the output - // lifetime except through this mutator. - unsafe { - $pb$::PrimitiveMut::from_inner( - $pbi$::Private, - $pbi$::RawVTableMutator::new( - $pbi$::Private, - self.as_mutator_message_ref(), - $Msg$::$vtable_name$, - ), - ) - } - } - )rs"); - } - }}, }, R"rs( $getter$ $getter_opt$ $setter$ $clearer$ - $vtable$ - $getter_mut$ )rs"); }