Implement Default::default() for owned messages.

PiperOrigin-RevId: 618758568
pull/16274/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent aa938dd958
commit 0c8f970fc9
  1. 2
      rust/test/shared/accessors_test.rs
  2. 6
      src/google/protobuf/compiler/rust/message.cc

@ -13,7 +13,7 @@ use unittest_proto::{test_all_types, TestAllTypes};
#[test]
fn test_default_accessors() {
let msg = TestAllTypes::new();
let msg: TestAllTypes = Default::default();
assert_that!(
msg,
matches_pattern!(TestAllTypes{

@ -815,6 +815,12 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
}
}
impl std::default::Default for $Msg$ {
fn default() -> Self {
Self::new()
}
}
// SAFETY:
// - `$Msg$` is `Sync` because it does not implement interior mutability.
// Neither does `$Msg$Mut`.

Loading…
Cancel
Save