Add impl Clone for Rust proto owned messages.

PiperOrigin-RevId: 633265290
pull/16832/head
Protobuf Team Bot 9 months ago committed by Copybara-Service
parent 7f23b700fe
commit 2238cdc091
  1. 12
      rust/test/shared/accessors_test.rs
  2. 6
      src/google/protobuf/compiler/rust/message.cc

@ -779,6 +779,18 @@ fn test_submsg_setter() {
assert_that!(parent.optional_nested_message().bb(), eq(7));
}
#[test]
fn test_clone() {
let mut m = TestAllTypes::new();
m.set_optional_int32(42);
let clone = m.clone();
assert_that!(clone.optional_int32(), eq(42));
m.clear_optional_int32();
assert_that!(m.has_optional_int32(), eq(false));
assert_that!(clone.has_optional_int32(), eq(true));
assert_that!(clone.optional_int32(), eq(42));
}
#[test]
fn test_to_owned() {
let mut m = TestAllTypes::new();

@ -1102,6 +1102,12 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
}
}
impl $std$::clone::Clone for $Msg$ {
fn clone(&self) -> Self {
self.as_view().to_owned()
}
}
extern "C" {
$Msg_externs$

Loading…
Cancel
Save