Skip to content

Commit 33f8721

Browse files
authored
fix some forgotten prost import paths (#1385)
1 parent efb0755 commit 33f8721

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

prost-build/src/code_generator.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,25 @@ impl<'b> CodeGenerator<'_, 'b> {
573573
));
574574
self.append_field_attributes(fq_message_name, field.descriptor.name());
575575
self.push_indent();
576-
self.buf.push_str(&format!(
577-
"pub {}: {}<{}, {}>,\n",
578-
field.rust_name(),
579-
map_type.rust_type(),
580-
key_ty,
581-
value_ty
582-
));
576+
match map_type {
577+
crate::MapType::HashMap => {
578+
self.buf.push_str(&format!(
579+
"pub {}: ::std::collections::HashMap<{}, {}>,\n",
580+
field.rust_name(),
581+
key_ty,
582+
value_ty
583+
));
584+
}
585+
crate::MapType::BTreeMap => {
586+
self.buf.push_str(&format!(
587+
"pub {}: {}::alloc::collections::BTreeMap<{}, {}>,\n",
588+
field.rust_name(),
589+
self.context.prost_path(),
590+
key_ty,
591+
value_ty
592+
));
593+
}
594+
}
583595
}
584596

585597
fn append_oneof_field(
@@ -685,8 +697,9 @@ impl<'b> CodeGenerator<'_, 'b> {
685697

686698
if boxed {
687699
self.buf.push_str(&format!(
688-
"{}(::prost::alloc::boxed::Box<{}>),\n",
700+
"{}({}::alloc::boxed::Box<{}>),\n",
689701
to_upper_camel(field.descriptor.name()),
702+
self.context.prost_path(),
690703
ty
691704
));
692705
} else {
@@ -983,11 +996,12 @@ impl<'b> CodeGenerator<'_, 'b> {
983996
Type::Int64 | Type::Sfixed64 | Type::Sint64 => String::from("i64"),
984997
Type::Bool => String::from("bool"),
985998
Type::String => format!("{}::alloc::string::String", self.context.prost_path()),
986-
Type::Bytes => self
987-
.context
988-
.bytes_type(fq_message_name, field.name())
989-
.rust_type()
990-
.to_owned(),
999+
Type::Bytes => match self.context.bytes_type(fq_message_name, field.name()) {
1000+
crate::BytesType::Vec => {
1001+
format!("{}::alloc::vec::Vec<u8>", self.context.prost_path())
1002+
}
1003+
crate::BytesType::Bytes => format!("{}::bytes::Bytes", self.context.prost_path()),
1004+
},
9911005
Type::Group | Type::Message => self.resolve_ident(field.type_name()),
9921006
}
9931007
}

prost-build/src/collections.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ impl MapType {
2828
MapType::BTreeMap => "btree_map",
2929
}
3030
}
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-
}
3931
}
4032

4133
impl BytesType {
@@ -46,12 +38,4 @@ impl BytesType {
4638
BytesType::Bytes => "bytes",
4739
}
4840
}
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-
}
5741
}

0 commit comments

Comments
 (0)