Skip to content

Commit 2aa859d

Browse files
committed
feat(prost-types): derive Arbitrary
Add feature to derive `trait Arbitrary` for each type.
1 parent 60d4c33 commit 2aa859d

File tree

7 files changed

+83
-1
lines changed

7 files changed

+83
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ jobs:
148148
uses: ./.github/actions/setup-ninja
149149
- uses: Swatinem/rust-cache@v2
150150
- name: test
151-
run: cargo test
151+
run: cargo test --features arbitrary
152152
- name: test no-default-features
153153
run: cargo test -p prost-build -p prost-derive -p prost-types --no-default-features
154154

prost-types/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ doctest = false
1515
[features]
1616
default = ["std"]
1717
std = ["prost/std"]
18+
arbitrary = ["dep:arbitrary"]
1819

1920
[dependencies]
2021
prost = { version = "0.13.4", path = "../prost", default-features = false, features = ["prost-derive"] }
22+
arbitrary = { version = "1.4", features = ["derive"], optional = true }
2123

2224
[dev-dependencies]
2325
proptest = "1"

prost-types/src/compiler.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This file is @generated by prost-build.
22
/// The version number of protocol compiler.
3+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
34
#[derive(Clone, PartialEq, ::prost::Message)]
45
pub struct Version {
56
#[prost(int32, optional, tag = "1")]
@@ -14,6 +15,7 @@ pub struct Version {
1415
pub suffix: ::core::option::Option<::prost::alloc::string::String>,
1516
}
1617
/// An encoded CodeGeneratorRequest is written to the plugin's stdin.
18+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1719
#[derive(Clone, PartialEq, ::prost::Message)]
1820
pub struct CodeGeneratorRequest {
1921
/// The .proto files that were explicitly listed on the command-line. The
@@ -45,6 +47,7 @@ pub struct CodeGeneratorRequest {
4547
pub compiler_version: ::core::option::Option<Version>,
4648
}
4749
/// The plugin writes an encoded CodeGeneratorResponse to stdout.
50+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
4851
#[derive(Clone, PartialEq, ::prost::Message)]
4952
pub struct CodeGeneratorResponse {
5053
/// Error message. If non-empty, code generation failed. The plugin process
@@ -67,6 +70,7 @@ pub struct CodeGeneratorResponse {
6770
/// Nested message and enum types in `CodeGeneratorResponse`.
6871
pub mod code_generator_response {
6972
/// Represents a single generated file.
73+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
7074
#[derive(Clone, PartialEq, ::prost::Message)]
7175
pub struct File {
7276
/// The file name, relative to the output directory. The name must not
@@ -131,6 +135,7 @@ pub mod code_generator_response {
131135
pub generated_code_info: ::core::option::Option<super::super::GeneratedCodeInfo>,
132136
}
133137
/// Sync with code_generator.h.
138+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
134139
#[derive(
135140
Clone,
136141
Copy,

prost-types/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
//!
3636
//! ## Feature Flags
3737
//! - `std`: Enable integration with standard library. Disable this feature for `no_std` support. This feature is enabled by default.
38+
//! - `arbitrary`: Enable integration with crate `arbitrary`. All types on this crate will implement `trait Arbitrary`.
3839
//!
3940
//! [1]: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf
4041

0 commit comments

Comments
 (0)