-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: derive Copy trait for messages where possible (#950)
* feat: derive Copy trait for messages where possible Rust primitive types can be copied by simply copying the bits. Rust structs can also have this property by deriving the Copy trait. Automatically derive Copy for: - messages that only have fields with primitive types - the Rust enum for one-of fields - messages whose field type are messages that also implement Copy Generated code for Protobuf enums already derives Copy. * fix: Remove clone call when copy is implemented Clippy reports: warning: using `clone` on type `Timestamp` which implements the `Copy` trait
- Loading branch information
1 parent
d42c85e
commit 85c698a
Showing
12 changed files
with
163 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
syntax = "proto3"; | ||
|
||
import "google/protobuf/timestamp.proto"; | ||
|
||
package derive_copy; | ||
|
||
message EmptyMsg {} | ||
|
||
message IntegerMsg { | ||
int32 field1 = 1; | ||
int64 field2 = 2; | ||
uint32 field3 = 3; | ||
uint64 field4 = 4; | ||
sint32 field5 = 5; | ||
sint64 field6 = 6; | ||
fixed32 field7 = 7; | ||
fixed64 field8 = 8; | ||
sfixed32 field9 = 9; | ||
sfixed64 field10 = 10; | ||
} | ||
|
||
message FloatMsg { | ||
double field1 = 1; | ||
float field2 = 2; | ||
} | ||
|
||
message BoolMsg { bool field1 = 1; } | ||
|
||
enum AnEnum { | ||
A = 0; | ||
B = 1; | ||
}; | ||
|
||
message EnumMsg { AnEnum field1 = 1; } | ||
|
||
message OneOfMsg { | ||
oneof data { | ||
int32 field1 = 1; | ||
int64 field2 = 2; | ||
} | ||
} | ||
|
||
message ComposedMsg { | ||
IntegerMsg field1 = 1; | ||
EnumMsg field2 = 2; | ||
OneOfMsg field3 = 3; | ||
} | ||
|
||
message WellKnownMsg { | ||
google.protobuf.Timestamp timestamp = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
include!(concat!(env!("OUT_DIR"), "/derive_copy.rs")); | ||
|
||
trait TestCopyIsImplemented: Copy {} | ||
|
||
impl TestCopyIsImplemented for EmptyMsg {} | ||
|
||
impl TestCopyIsImplemented for IntegerMsg {} | ||
|
||
impl TestCopyIsImplemented for FloatMsg {} | ||
|
||
impl TestCopyIsImplemented for BoolMsg {} | ||
|
||
impl TestCopyIsImplemented for AnEnum {} | ||
|
||
impl TestCopyIsImplemented for EnumMsg {} | ||
|
||
impl TestCopyIsImplemented for OneOfMsg {} | ||
|
||
impl TestCopyIsImplemented for ComposedMsg {} | ||
|
||
impl TestCopyIsImplemented for WellKnownMsg {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters