Skip to main content

JsonParseOptions

Struct JsonParseOptions 

Source
#[non_exhaustive]
pub struct JsonParseOptions { pub ignore_unknown_enum_values: bool, pub strict_extension_keys: bool, }
Available on crate feature json only.
Expand description

Options controlling protobuf JSON parsing behavior.

Use JsonParseOptions::new plus builder methods to construct:

let opts = JsonParseOptions::new().ignore_unknown_enum_values(true);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§ignore_unknown_enum_values: bool

When true, unknown enum string values are silently replaced with the default value (0) for singular fields, or skipped for repeated/map fields, instead of producing an error.

§strict_extension_keys: bool

When true, "[pkg.ext]" JSON keys that are not in the extension registry produce a parse error instead of being silently dropped.

The default (false, lenient) matches the pre-extension-registry behavior where all unknown keys were dropped by serde’s derive. protobuf-go (protojson/decode.go:175) and protobuf-es (from-json.ts:251) both error on unregistered extension keys unless their respective ignore-unknown flags are set; set true here to match. The error pinpoints the missing registration.

Extendee mismatch (key IS registered but extends a different message) always errors regardless of this flag — that’s a contract violation, not a mere miss.

Implementations§

Source§

impl JsonParseOptions

Source

pub fn new() -> Self

Create new parse options with all flags at their default (strict) values.

Source

pub fn ignore_unknown_enum_values(self, ignore: bool) -> Self

Set whether unknown enum string values are ignored (replaced with the default) instead of producing a parse error.

Source

pub fn strict_extension_keys(self, strict: bool) -> Self

Set whether unregistered "[pkg.ext]" JSON keys produce a parse error (true) or are silently dropped (false, the default).

Trait Implementations§

Source§

impl Clone for JsonParseOptions

Source§

fn clone(&self) -> JsonParseOptions

Returns a duplicate 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 JsonParseOptions

Source§

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

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

impl Default for JsonParseOptions

Source§

fn default() -> JsonParseOptions

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

impl PartialEq for JsonParseOptions

Source§

fn eq(&self, other: &JsonParseOptions) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for JsonParseOptions

Source§

impl Eq for JsonParseOptions

Source§

impl StructuralPartialEq for JsonParseOptions

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 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.