Skip to main content

CanonicalJsonObjectExt

Trait CanonicalJsonObjectExt 

Source
pub trait CanonicalJsonObjectExt {
    // Required methods
    fn get_as_object(
        &self,
        field: &str,
        path: impl Into<String>,
    ) -> Result<Option<&BTreeMap<String, CanonicalJsonValue>>, CanonicalJsonFieldError>;
    fn get_as_object_mut(
        &mut self,
        field: &str,
        path: impl Into<String>,
    ) -> Result<Option<&mut BTreeMap<String, CanonicalJsonValue>>, CanonicalJsonFieldError>;
    fn get_as_object_or_insert_default(
        &mut self,
        field: impl Into<String>,
        path: impl Into<String>,
    ) -> Result<&mut BTreeMap<String, CanonicalJsonValue>, CanonicalJsonFieldError>;
    fn get_as_string(
        &self,
        field: &str,
        path: impl Into<String>,
    ) -> Result<Option<&str>, CanonicalJsonFieldError>;

    // Provided methods
    fn get_as_required_object(
        &self,
        field: &str,
        path: impl Into<String>,
    ) -> Result<&BTreeMap<String, CanonicalJsonValue>, CanonicalJsonFieldError> { ... }
    fn get_as_required_object_mut(
        &mut self,
        field: &str,
        path: impl Into<String>,
    ) -> Result<&mut BTreeMap<String, CanonicalJsonValue>, CanonicalJsonFieldError> { ... }
    fn get_as_required_string(
        &self,
        field: &str,
        path: impl Into<String>,
    ) -> Result<&str, CanonicalJsonFieldError> { ... }
}
Expand description

Helper trait to interact with a CanonicalJsonObject.

Required Methods§

Source

fn get_as_object( &self, field: &str, path: impl Into<String>, ) -> Result<Option<&BTreeMap<String, CanonicalJsonValue>>, CanonicalJsonFieldError>

Get the given field as an object.

§Parameters
  • field: The name of the field to access.
  • path: The full path of the field that will be used in errors. This can be different than the field, to clarify if this is a field nested under several objects.
§Errors

Returns an error if the field is invalid.

Source

fn get_as_object_mut( &mut self, field: &str, path: impl Into<String>, ) -> Result<Option<&mut BTreeMap<String, CanonicalJsonValue>>, CanonicalJsonFieldError>

Get the given field as a mutable object.

§Parameters
  • field: The name of the field to access.
  • path: The full path of the field that will be used in errors. This can be different than the field, to clarify if this is a field nested under several objects.
§Errors

Returns an error if the field is invalid.

Source

fn get_as_object_or_insert_default( &mut self, field: impl Into<String>, path: impl Into<String>, ) -> Result<&mut BTreeMap<String, CanonicalJsonValue>, CanonicalJsonFieldError>

Get the given required field as a mutable object or insert it if it is missing.

§Parameters
  • field: The name of the field to access.
  • path: The full path of the field that will be used in errors. This can be different than the field, to clarify if this is a field nested under several objects.
§Errors

Returns an error if the field is already be present but invalid.

Source

fn get_as_string( &self, field: &str, path: impl Into<String>, ) -> Result<Option<&str>, CanonicalJsonFieldError>

Get the given field as a string.

§Parameters
  • field: The name of the field to access.
  • path: The full path of the field that will be used in errors. This can be different than the field, to clarify if this is a field nested under several objects.
§Errors

Returns an error if the field is invalid.

Provided Methods§

Source

fn get_as_required_object( &self, field: &str, path: impl Into<String>, ) -> Result<&BTreeMap<String, CanonicalJsonValue>, CanonicalJsonFieldError>

Get the given required field as an object.

§Parameters
  • field: The name of the field to access.
  • path: The full path of the field that will be used in errors. This can be different than the field, to clarify if this is a field nested under several objects.
§Errors

Returns an error if the field is missing or invalid.

Source

fn get_as_required_object_mut( &mut self, field: &str, path: impl Into<String>, ) -> Result<&mut BTreeMap<String, CanonicalJsonValue>, CanonicalJsonFieldError>

Get the given required field as a mutable object.

§Parameters
  • field: The name of the field to access.
  • path: The full path of the field that will be used in errors. This can be different than the field, to clarify if this is a field nested under several objects.
§Errors

Returns an error if the field is missing or invalid.

Source

fn get_as_required_string( &self, field: &str, path: impl Into<String>, ) -> Result<&str, CanonicalJsonFieldError>

Get the given required field as a string.

§Parameters
  • field: The name of the field to access.
  • path: The full path of the field that will be used in errors. This can be different than the field, to clarify if this is a field nested under several objects.
§Errors

Returns an error if the field is missing or invalid.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl CanonicalJsonObjectExt for BTreeMap<String, CanonicalJsonValue>

Implementors§