Skip to main content

CanonicalJsonObjectExt

Trait CanonicalJsonObjectExt 

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§

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.

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.

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.

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§

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.

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.

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", so this trait is not object safe.

Implementations on Foreign Types§

§

impl CanonicalJsonObjectExt for BTreeMap<String, CanonicalJsonValue>

Implementors§