|
| 1 | +/// The map collection type to output for Protobuf `map` fields. |
| 2 | +#[non_exhaustive] |
| 3 | +#[derive(Default, Clone, Copy, Debug, PartialEq)] |
| 4 | +pub(crate) enum MapType { |
| 5 | + /// The [`std::collections::HashMap`] type. |
| 6 | + #[default] |
| 7 | + HashMap, |
| 8 | + /// The [`std::collections::BTreeMap`] type. |
| 9 | + BTreeMap, |
| 10 | +} |
| 11 | + |
| 12 | +/// The bytes collection type to output for Protobuf `bytes` fields. |
| 13 | +#[non_exhaustive] |
| 14 | +#[derive(Default, Clone, Copy, Debug, PartialEq)] |
| 15 | +pub(crate) enum BytesType { |
| 16 | + /// The [`alloc::collections::Vec::<u8>`] type. |
| 17 | + #[default] |
| 18 | + Vec, |
| 19 | + /// The [`bytes::Bytes`] type. |
| 20 | + Bytes, |
| 21 | +} |
| 22 | + |
| 23 | +impl MapType { |
| 24 | + /// The `prost-derive` annotation type corresponding to the map type. |
| 25 | + pub fn annotation(&self) -> &'static str { |
| 26 | + match self { |
| 27 | + MapType::HashMap => "map", |
| 28 | + MapType::BTreeMap => "btree_map", |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + /// The fully-qualified Rust type corresponding to the map type. |
| 33 | + pub fn rust_type(&self) -> &'static str { |
| 34 | + match self { |
| 35 | + MapType::HashMap => "::std::collections::HashMap", |
| 36 | + MapType::BTreeMap => "::prost::alloc::collections::BTreeMap", |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +impl BytesType { |
| 42 | + /// The `prost-derive` annotation type corresponding to the bytes type. |
| 43 | + pub fn annotation(&self) -> &'static str { |
| 44 | + match self { |
| 45 | + BytesType::Vec => "vec", |
| 46 | + BytesType::Bytes => "bytes", |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + /// The fully-qualified Rust type corresponding to the bytes type. |
| 51 | + pub fn rust_type(&self) -> &'static str { |
| 52 | + match self { |
| 53 | + BytesType::Vec => "::prost::alloc::vec::Vec<u8>", |
| 54 | + BytesType::Bytes => "::prost::bytes::Bytes", |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments