Skip to content

Commit

Permalink
Emit setters on primitive scalars without presence
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 589840802
  • Loading branch information
Necior authored and copybara-github committed Dec 11, 2023
1 parent f85b347 commit d605b48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rust/test/shared/accessors_proto3_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ fn test_fixed32_accessors() {
msg.optional_fixed32_mut().set(u32::default());
assert_that!(msg.optional_fixed32(), eq(0));
assert_that!(msg.optional_fixed32_mut().get(), eq(0));

msg.optional_fixed32_set(43);
assert_that!(msg.optional_fixed32(), eq(43));
assert_that!(msg.optional_fixed32_mut().get(), eq(43));
}

#[test]
Expand All @@ -41,6 +45,10 @@ fn test_bool_accessors() {
msg.optional_bool_mut().set(bool::default());
assert_that!(msg.optional_bool(), eq(false));
assert_that!(msg.optional_bool_mut().get(), eq(false));

msg.optional_bool_set(true);
assert_that!(msg.optional_bool(), eq(true));
assert_that!(msg.optional_bool_mut().get(), eq(true));
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ void SingularScalar::InMsgImpl(Context<FieldDescriptor> field) const {
}
}
)rs");
} else {
field.Emit({}, R"rs(
pub fn r#$field$_set(&mut self, val: $Scalar$) {
unsafe { $setter_thunk$(self.inner.msg, val) }
}
)rs");
}
}},
{"field_mutator_getter",
Expand Down

0 comments on commit d605b48

Please sign in to comment.