Skip to main content

TypeRegistry

Struct TypeRegistry 

Source
pub struct TypeRegistry { /* private fields */ }
Available on crate features json or text only.
Expand description

Unified registry: JSON Any + extension entries (under json) and text Any + extension entries (under text).

Populate with generated register_types(&mut reg) functions, then install once with set_type_registry. The JSON half delegates to the existing AnyRegistry and ExtensionRegistry types; the text half uses parallel maps. Both axes’ lookup indirection (by_name → by_number) is preserved.

Implementations§

Source§

impl TypeRegistry

Source

pub fn new() -> Self

Creates an empty registry.

Source

pub fn register_json_any(&mut self, entry: JsonAnyEntry)

Available on crate feature json only.

Registers a JSON Any type entry.

Replaces any existing entry for the same type URL. When the same message full name is registered under several URLs, a json_any_by_url lookup of a URL that is not itself registered uses the most recently registered one.

A lookup by name decodes the payload as this message. A payload under another prefix that does not decode as it fails to serialize as JSON; one that does decode is written with this message’s fields.

Source

pub fn register_json_ext(&mut self, entry: JsonExtEntry)

Available on crate feature json only.

Registers a JSON extension entry. Replaces any existing entry at the same (extendee, number) or full_name.

Source

pub fn register_text_any(&mut self, entry: TextAnyEntry)

Available on crate feature text only.

Registers a text Any type entry.

Replaces any existing entry for the same type URL. When the same message full name is registered under several URLs, a text_any_by_url lookup of a URL that is not itself registered uses the most recently registered one.

A lookup by name decodes the payload as this message. A payload under another prefix that does not decode as it prints with an empty body; one that does decode is written with this message’s fields.

Source

pub fn register_text_ext(&mut self, entry: TextExtEntry)

Available on crate feature text only.

Registers a text extension entry. Replaces any existing entry at the same (extendee, number) or full_name.

Source

pub fn json_any_by_url(&self, type_url: &str) -> Option<&JsonAnyEntry>

Available on crate feature json only.

Look up a JSON Any entry by type URL.

A registered URL finds its own entry. Any other URL is matched by the message full name after its last /, and a string without a / as a bare full name. The entry’s type_url is the registered one, so keep the URL you looked up as the Any’s type_url.

Source

pub fn json_ext_by_number( &self, extendee: &str, number: u32, ) -> Option<&JsonExtEntry>

Available on crate feature json only.

Look up a JSON extension entry by (extendee, number).

Source

pub fn json_ext_by_name(&self, full_name: &str) -> Option<&JsonExtEntry>

Available on crate feature json only.

Look up a JSON extension entry by full name.

Source

pub fn text_any_by_url(&self, type_url: &str) -> Option<&TextAnyEntry>

Available on crate feature text only.

Look up a text Any entry by type URL.

A registered URL finds its own entry. Any other URL is matched by the message full name after its last /. A string without a / is found only by an exact match, unlike in json_any_by_url. The entry’s type_url is the registered one, so keep the URL you looked up as the Any’s type_url.

Source

pub fn text_ext_by_number( &self, extendee: &str, number: u32, ) -> Option<&TextExtEntry>

Available on crate feature text only.

Look up a text extension entry by (extendee, number).

Source

pub fn text_ext_by_name(&self, full_name: &str) -> Option<&TextExtEntry>

Available on crate feature text only.

Look up a text extension entry by full name.

Trait Implementations§

Source§

impl Debug for TypeRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TypeRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.