-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prost_build:
BytesType and MapType
into a collections
module.
- Loading branch information
Showing
3 changed files
with
60 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/// The map collection type to output for Protobuf `map` fields. | ||
#[non_exhaustive] | ||
#[derive(Default, Clone, Copy, Debug, PartialEq)] | ||
pub(crate) enum MapType { | ||
/// The [`std::collections::HashMap`] type. | ||
#[default] | ||
HashMap, | ||
/// The [`std::collections::BTreeMap`] type. | ||
BTreeMap, | ||
} | ||
|
||
/// The bytes collection type to output for Protobuf `bytes` fields. | ||
#[non_exhaustive] | ||
#[derive(Default, Clone, Copy, Debug, PartialEq)] | ||
pub(crate) enum BytesType { | ||
/// The [`alloc::collections::Vec::<u8>`] type. | ||
#[default] | ||
Vec, | ||
/// The [`bytes::Bytes`] type. | ||
Bytes, | ||
} | ||
|
||
impl MapType { | ||
/// The `prost-derive` annotation type corresponding to the map type. | ||
pub fn annotation(&self) -> &'static str { | ||
match self { | ||
MapType::HashMap => "map", | ||
MapType::BTreeMap => "btree_map", | ||
} | ||
} | ||
|
||
/// The fully-qualified Rust type corresponding to the map type. | ||
pub fn rust_type(&self) -> &'static str { | ||
match self { | ||
MapType::HashMap => "::std::collections::HashMap", | ||
MapType::BTreeMap => "::prost::alloc::collections::BTreeMap", | ||
} | ||
} | ||
} | ||
|
||
impl BytesType { | ||
/// The `prost-derive` annotation type corresponding to the bytes type. | ||
pub fn annotation(&self) -> &'static str { | ||
match self { | ||
BytesType::Vec => "vec", | ||
BytesType::Bytes => "bytes", | ||
} | ||
} | ||
|
||
/// The fully-qualified Rust type corresponding to the bytes type. | ||
pub fn rust_type(&self) -> &'static str { | ||
match self { | ||
BytesType::Vec => "::prost::alloc::vec::Vec<u8>", | ||
BytesType::Bytes => "::prost::bytes::Bytes", | ||
} | ||
} | ||
} |
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