From 3381c8a89df2e938717d277259515f81e0879766 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Wed, 15 Jan 2020 16:45:24 -0500 Subject: [PATCH] Add `iter_messages` and `iter_enums` to `Descriptor` These functions make it possible to discover what messages and enums are available in the descriptor set when you don't know their names ahead of time. Co-authored-by: Nikhil Benesch --- src/descriptor.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/descriptor.rs b/src/descriptor.rs index 01110b2..86ff8c0 100644 --- a/src/descriptor.rs +++ b/src/descriptor.rs @@ -342,12 +342,26 @@ impl Descriptors { self.messages_by_name.get(name).map(|m| &self.messages[m.0]) } + /// Iterates over the messages in the descriptor set. + /// + /// The order of iteration is unspecified. + pub fn iter_messages(&self) -> impl Iterator { + self.messages.iter() + } + /// Looks up an enum by its fully qualified name (i.e. `.foo.package.Enum`). #[inline] pub fn enum_by_name(&self, name: &str) -> Option<&EnumDescriptor> { self.enums_by_name.get(name).map(|e| &self.enums[e.0]) } + /// Iterates over the enums in the descriptor set. + /// + /// The order of iteration is unspecified. + pub fn iter_enums(&self) -> impl Iterator { + self.enums.iter() + } + /// Adds all types defined in the specified protocol buffer file descriptor set to this /// registry. pub fn add_file_set_proto(&mut self, file_set_proto: &descriptor::FileDescriptorSet) {