Skip to main content

DataValueValidator

Struct DataValueValidator 

Source
pub struct DataValueValidator { /* private fields */ }
Expand description

A declaration closure used to validate Morphir data without I/O.

Build this from the supplied V3 or V4 distribution, then validate the predicate’s declared type. Semantic interpreters, including target-name language-ID policy, run separately after this shared shape check.

§Example

use indexmap::IndexMap;
use morphir_core::data_value::DataValueValidator;
use morphir_core::ir::v4;
use morphir_core::naming::{FQName, PackageName, Path};

let distribution = v4::Distribution::Specs(v4::SpecsContent {
    package_name: PackageName::new(Path::new("example")),
    dependencies: IndexMap::new(),
    spec: v4::PackageSpecification { modules: IndexMap::new() },
});
let string = v4::Type::reference(
    v4::TypeAttributes::default(),
    FQName::from_canonical_string("morphir/SDK:string#string")?,
    vec![],
);
let validator = DataValueValidator::v4(&distribution)?;
assert!(validator.validate_v4_data(&string, &serde_json::json!("order")).is_ok());

Implementations§

Source§

impl DataValueValidator

Source

pub fn v4(distribution: &Distribution) -> Result<Self, DataValueError>

Collect all type definitions and specifications visible to a V4 distribution.

Source

pub fn v3(distribution: &Distribution) -> Result<Self, DataValueError>

Collect all type definitions and specifications visible to a V3 distribution.

Source

pub fn validate_v4_data( &self, ty: &Type, value: &Value, ) -> Result<(), DataValueError>

Validate one V4 data value against a declared Morphir type.

Source

pub fn validate_v3_data( &self, ty: &Type<Attrs>, value: &Value, ) -> Result<(), DataValueError>

Validate one V3 data value against a declared Morphir type.

Source

pub fn validate_v4_object( &self, ty: &Type, object: &ObjectTerm, ) -> Result<(), DataValueError>

Validate a V4 metadata object only when it is a data term.

Source

pub fn validate_reference( &self, name: &FQName, value: &Value, ) -> Result<(), DataValueError>

Validate a named type entry point, as used by decorator sidecars.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.