pub struct FormatOptions { /* private fields */ }
Available on crate feature text-format only.
Expand description

Options to control printing of the protobuf text format.

Used by DynamicMessage::to_text_format_with_options().

Implementations§

source§

impl FormatOptions

source

pub fn new() -> Self

Creates new instance of FormatOptions with default options.

source

pub fn pretty(self, yes: bool) -> Self

Whether to prettify the format output.

If set to true, each field will be printed on a new line, and nested messages will be indented.

The default value is false.

source

pub fn skip_unknown_fields(self, yes: bool) -> Self

Whether to include unknown fields in the output.

If set to false, unknown fields will be printed. The protobuf format does not include type information, so the formatter will attempt to infer types.

The default value is true.

Examples
let dynamic_message = DynamicMessage::decode(message_descriptor, b"\x08\x96\x01\x1a\x02\x10\x42".as_ref()).unwrap();
assert_eq!(dynamic_message.to_text_format(), "");
let options = FormatOptions::new().skip_unknown_fields(false);
assert_eq!(dynamic_message.to_text_format_with_options(&options), "1:150,3{2:66}");
source

pub fn expand_any(self, yes: bool) -> Self

Whether to use the expanded form of the google.protobuf.Any type.

If set to true, Any fields will use an expanded form:

[type.googleapis.com/package.MyMessage] {
  foo: 150
}

If set to false, the normal text format representation will be used:

type_url: "type.googleapis.com/package.MyMessage"
value: "\x08\x96\x01"

The default value is true.

Examples
let message_descriptor = pool.get_message_by_name("google.protobuf.Any").unwrap();
let mut dynamic_message = DynamicMessage::new(message_descriptor);
dynamic_message.set_field_by_name("type_url", Value::String("type.googleapis.com/package.MyMessage".to_owned()));
dynamic_message.set_field_by_name("value", Value::Bytes(Bytes::from_static(b"\x08\x96\x01\x1a\x02\x10\x42".as_ref())));

assert_eq!(dynamic_message.to_text_format(), "[type.googleapis.com/package.MyMessage]{foo:150,nested{bar:66}}");
let options = FormatOptions::new().expand_any(false);
assert_eq!(dynamic_message.to_text_format_with_options(&options), r#"type_url:"type.googleapis.com/package.MyMessage",value:"\010\226\001\032\002\020B""#);

Trait Implementations§

source§

impl Clone for FormatOptions

source§

fn clone(&self) -> FormatOptions

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for FormatOptions

source§

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

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

impl Default for FormatOptions

source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.