-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prost-build: support boxing fields (#802)
This allows the user to request boxing of specific fields. This is useful for enum types that might have variants of very different size.
- Loading branch information
1 parent
d5395ba
commit 7b6742b
Showing
5 changed files
with
166 additions
and
6 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
33 changes: 33 additions & 0 deletions
33
prost-build/src/fixtures/field_attributes/_expected_field_attributes.rs
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,33 @@ | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Container { | ||
#[prost(oneof="container::Data", tags="1, 2")] | ||
pub data: ::core::option::Option<container::Data>, | ||
} | ||
/// Nested message and enum types in `Container`. | ||
pub mod container { | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Oneof)] | ||
pub enum Data { | ||
#[prost(message, tag="1")] | ||
Foo(::prost::alloc::boxed::Box<super::Foo>), | ||
#[prost(message, tag="2")] | ||
Bar(super::Bar), | ||
} | ||
} | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Foo { | ||
#[prost(string, tag="1")] | ||
pub foo: ::prost::alloc::string::String, | ||
} | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Bar { | ||
#[prost(message, optional, boxed, tag="1")] | ||
pub qux: ::core::option::Option<::prost::alloc::boxed::Box<Qux>>, | ||
} | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Qux { | ||
} |
32 changes: 32 additions & 0 deletions
32
prost-build/src/fixtures/field_attributes/_expected_field_attributes_formatted.rs
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,32 @@ | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Container { | ||
#[prost(oneof = "container::Data", tags = "1, 2")] | ||
pub data: ::core::option::Option<container::Data>, | ||
} | ||
/// Nested message and enum types in `Container`. | ||
pub mod container { | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Oneof)] | ||
pub enum Data { | ||
#[prost(message, tag = "1")] | ||
Foo(::prost::alloc::boxed::Box<super::Foo>), | ||
#[prost(message, tag = "2")] | ||
Bar(super::Bar), | ||
} | ||
} | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Foo { | ||
#[prost(string, tag = "1")] | ||
pub foo: ::prost::alloc::string::String, | ||
} | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Bar { | ||
#[prost(message, optional, boxed, tag = "1")] | ||
pub qux: ::core::option::Option<::prost::alloc::boxed::Box<Qux>>, | ||
} | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct Qux {} |
21 changes: 21 additions & 0 deletions
21
prost-build/src/fixtures/field_attributes/field_attributes.proto
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 @@ | ||
syntax = "proto3"; | ||
|
||
package field_attributes; | ||
|
||
message Container { | ||
oneof data { | ||
Foo foo = 1; | ||
Bar bar = 2; | ||
} | ||
} | ||
|
||
message Foo { | ||
string foo = 1; | ||
} | ||
|
||
message Bar { | ||
Qux qux = 1; | ||
} | ||
|
||
message Qux { | ||
} |
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