Skip to content

Commit

Permalink
feat(prost-types): derive Arbitrary
Browse files Browse the repository at this point in the history
Add feature to derive `trait Arbitrary` for each type.
  • Loading branch information
caspermeijn committed Dec 6, 2024
1 parent 60d4c33 commit 2aa859d
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
uses: ./.github/actions/setup-ninja
- uses: Swatinem/rust-cache@v2
- name: test
run: cargo test
run: cargo test --features arbitrary
- name: test no-default-features
run: cargo test -p prost-build -p prost-derive -p prost-types --no-default-features

Expand Down
2 changes: 2 additions & 0 deletions prost-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ doctest = false
[features]
default = ["std"]
std = ["prost/std"]
arbitrary = ["dep:arbitrary"]

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

[dev-dependencies]
proptest = "1"
Expand Down
5 changes: 5 additions & 0 deletions prost-types/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This file is @generated by prost-build.
/// The version number of protocol compiler.
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Version {
#[prost(int32, optional, tag = "1")]
Expand All @@ -14,6 +15,7 @@ pub struct Version {
pub suffix: ::core::option::Option<::prost::alloc::string::String>,
}
/// An encoded CodeGeneratorRequest is written to the plugin's stdin.
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CodeGeneratorRequest {
/// The .proto files that were explicitly listed on the command-line. The
Expand Down Expand Up @@ -45,6 +47,7 @@ pub struct CodeGeneratorRequest {
pub compiler_version: ::core::option::Option<Version>,
}
/// The plugin writes an encoded CodeGeneratorResponse to stdout.
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CodeGeneratorResponse {
/// Error message. If non-empty, code generation failed. The plugin process
Expand All @@ -67,6 +70,7 @@ pub struct CodeGeneratorResponse {
/// Nested message and enum types in `CodeGeneratorResponse`.
pub mod code_generator_response {
/// Represents a single generated file.
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct File {
/// The file name, relative to the output directory. The name must not
Expand Down Expand Up @@ -131,6 +135,7 @@ pub mod code_generator_response {
pub generated_code_info: ::core::option::Option<super::super::GeneratedCodeInfo>,
}
/// Sync with code_generator.h.
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(
Clone,
Copy,
Expand Down
1 change: 1 addition & 0 deletions prost-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
//!
//! ## Feature Flags
//! - `std`: Enable integration with standard library. Disable this feature for `no_std` support. This feature is enabled by default.
//! - `arbitrary`: Enable integration with crate `arbitrary`. All types on this crate will implement `trait Arbitrary`.
//!
//! [1]: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf
Expand Down
Loading

0 comments on commit 2aa859d

Please sign in to comment.