diff --git a/prost-build/src/code_generator.rs b/prost-build/src/code_generator.rs index 1f22acbe2..ef6c15b34 100644 --- a/prost-build/src/code_generator.rs +++ b/prost-build/src/code_generator.rs @@ -573,13 +573,25 @@ impl<'b> CodeGenerator<'_, 'b> { )); self.append_field_attributes(fq_message_name, field.descriptor.name()); self.push_indent(); - self.buf.push_str(&format!( - "pub {}: {}<{}, {}>,\n", - field.rust_name(), - map_type.rust_type(), - key_ty, - value_ty - )); + match map_type { + crate::MapType::HashMap => { + self.buf.push_str(&format!( + "pub {}: ::std::collections::HashMap<{}, {}>,\n", + field.rust_name(), + key_ty, + value_ty + )); + } + crate::MapType::BTreeMap => { + self.buf.push_str(&format!( + "pub {}: {}::alloc::collections::BTreeMap<{}, {}>,\n", + field.rust_name(), + self.context.prost_path(), + key_ty, + value_ty + )); + } + } } fn append_oneof_field( @@ -685,8 +697,9 @@ impl<'b> CodeGenerator<'_, 'b> { if boxed { self.buf.push_str(&format!( - "{}(::prost::alloc::boxed::Box<{}>),\n", + "{}({}::alloc::boxed::Box<{}>),\n", to_upper_camel(field.descriptor.name()), + self.context.prost_path(), ty )); } else { @@ -983,11 +996,12 @@ impl<'b> CodeGenerator<'_, 'b> { Type::Int64 | Type::Sfixed64 | Type::Sint64 => String::from("i64"), Type::Bool => String::from("bool"), Type::String => format!("{}::alloc::string::String", self.context.prost_path()), - Type::Bytes => self - .context - .bytes_type(fq_message_name, field.name()) - .rust_type() - .to_owned(), + Type::Bytes => match self.context.bytes_type(fq_message_name, field.name()) { + crate::BytesType::Vec => { + format!("{}::alloc::vec::Vec", self.context.prost_path()) + } + crate::BytesType::Bytes => format!("{}::bytes::Bytes", self.context.prost_path()), + }, Type::Group | Type::Message => self.resolve_ident(field.type_name()), } } diff --git a/prost-build/src/collections.rs b/prost-build/src/collections.rs index e55625cf3..29a635c23 100644 --- a/prost-build/src/collections.rs +++ b/prost-build/src/collections.rs @@ -28,14 +28,6 @@ impl MapType { 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 { @@ -46,12 +38,4 @@ impl BytesType { 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", - BytesType::Bytes => "::prost::bytes::Bytes", - } - } }