Struct prost_reflect::DescriptorPool
source · [−]pub struct DescriptorPool { /* private fields */ }Expand description
A DescriptorPool is a collection of related descriptors. Typically it will be created from
a FileDescriptorSet output by the protobuf compiler (see DescriptorPool::from_file_descriptor_set)
but it may also be built up manually by adding individual files.
Methods like MessageDescriptor::extensions will be scoped to just the files contained within the parent
DescriptorPool.
This type is uses reference counting internally so it is cheap to clone. Modifying an instance of a pool will not update any existing clones of the instance.
Implementations
sourceimpl DescriptorPool
impl DescriptorPool
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty DescriptorPool.
For the common case of creating a DescriptorPool from a single FileDescriptorSet, see
DescriptorPool::from_file_descriptor_set or DescriptorPool::decode.
sourcepub fn from_file_descriptor_set(
file_descriptor_set: FileDescriptorSet
) -> Result<Self, DescriptorError>
pub fn from_file_descriptor_set(
file_descriptor_set: FileDescriptorSet
) -> Result<Self, DescriptorError>
Creates a DescriptorPool from a FileDescriptorSet.
This is equivalent to calling DescriptorPool::add_file_descriptor_set on an empty DescriptorPool
instance. See that method’s documentation for details.
sourcepub fn decode<B>(bytes: B) -> Result<Self, DescriptorError> where
B: Buf,
pub fn decode<B>(bytes: B) -> Result<Self, DescriptorError> where
B: Buf,
Decodes a FileDescriptorSet from its protobuf byte representation and
creates a new DescriptorPool wrapping it.
sourcepub fn add_file_descriptor_set(
&mut self,
file_descriptor_set: FileDescriptorSet
) -> Result<(), DescriptorError>
pub fn add_file_descriptor_set(
&mut self,
file_descriptor_set: FileDescriptorSet
) -> Result<(), DescriptorError>
Adds a new FileDescriptorSet to this DescriptorPool.
A file descriptor set may be generated by running the protobuf compiler with the
--descriptor_set_out flag. If you are using prost-build,
then Config::file_descriptor_set_path
is a convenient way to generated it as part of your build.
This method may return an error if file_descriptor_set is invalid, for example
it contains references to types not in the set. If file_descriptor_set was created by
the protobuf compiler, these error cases should never occur since it performs its own
validation.
sourcepub fn add_file_descriptor_protos<I>(
&mut self,
files: I
) -> Result<(), DescriptorError> where
I: IntoIterator<Item = FileDescriptorProto>,
pub fn add_file_descriptor_protos<I>(
&mut self,
files: I
) -> Result<(), DescriptorError> where
I: IntoIterator<Item = FileDescriptorProto>,
Adds a collection of file descriptors to this pool.
The file descriptors may be provided in any order, however all types referenced must be defined either in one of the files provided, or in a file previously added to the pool.
Duplicate file descriptors are ignored, however adding two different files with the same name will return an error.
sourcepub fn add_file_descriptor_proto(
&mut self,
file: FileDescriptorProto
) -> Result<(), DescriptorError>
pub fn add_file_descriptor_proto(
&mut self,
file: FileDescriptorProto
) -> Result<(), DescriptorError>
Add a single file descriptor to the pool.
All types referenced by the file must be defined either in the file itself, or in a file previously added to the pool.
sourcepub fn file_descriptor_protos(
&self
) -> impl ExactSizeIterator<Item = &FileDescriptorProto> + '_
pub fn file_descriptor_protos(
&self
) -> impl ExactSizeIterator<Item = &FileDescriptorProto> + '_
Gets a iterator over the raw FileDescriptorProto instances wrapped by this DescriptorPool.
sourcepub fn services(&self) -> impl ExactSizeIterator<Item = ServiceDescriptor> + '_
pub fn services(&self) -> impl ExactSizeIterator<Item = ServiceDescriptor> + '_
Gets an iterator over the services defined in these protobuf files.
sourcepub fn all_messages(
&self
) -> impl ExactSizeIterator<Item = MessageDescriptor> + '_
pub fn all_messages(
&self
) -> impl ExactSizeIterator<Item = MessageDescriptor> + '_
Gets an iterator over all messages defined in these protobuf files.
The iterator includes nested messages defined in another message.
sourcepub fn all_enums(&self) -> impl ExactSizeIterator<Item = EnumDescriptor> + '_
pub fn all_enums(&self) -> impl ExactSizeIterator<Item = EnumDescriptor> + '_
Gets an iterator over all enums defined in these protobuf files.
The iterator includes nested enums defined in another message.
sourcepub fn all_extensions(
&self
) -> impl ExactSizeIterator<Item = ExtensionDescriptor> + '_
pub fn all_extensions(
&self
) -> impl ExactSizeIterator<Item = ExtensionDescriptor> + '_
Gets an iterator over all extension fields defined in these protobuf files.
The iterator includes nested extension fields defined in another message.
sourcepub fn get_message_by_name(&self, name: &str) -> Option<MessageDescriptor>
pub fn get_message_by_name(&self, name: &str) -> Option<MessageDescriptor>
Gets a MessageDescriptor by its fully qualified name, for example my.package.MessageName.
sourcepub fn get_enum_by_name(&self, name: &str) -> Option<EnumDescriptor>
pub fn get_enum_by_name(&self, name: &str) -> Option<EnumDescriptor>
Gets an EnumDescriptor by its fully qualified name, for example my.package.EnumName.
Trait Implementations
sourceimpl Clone for DescriptorPool
impl Clone for DescriptorPool
sourcefn clone(&self) -> DescriptorPool
fn clone(&self) -> DescriptorPool
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for DescriptorPool
impl Debug for DescriptorPool
sourceimpl Default for DescriptorPool
impl Default for DescriptorPool
sourcefn default() -> DescriptorPool
fn default() -> DescriptorPool
Returns the “default value” for a type. Read more
sourceimpl PartialEq<DescriptorPool> for DescriptorPool
impl PartialEq<DescriptorPool> for DescriptorPool
impl Eq for DescriptorPool
Auto Trait Implementations
impl RefUnwindSafe for DescriptorPool
impl Send for DescriptorPool
impl Sync for DescriptorPool
impl Unpin for DescriptorPool
impl UnwindSafe for DescriptorPool
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more