Skip to main content

ValueSchema

Trait ValueSchema 

Source
pub trait ValueSchema:
    ConstId
    + Sized
    + 'static {
    type ValidationError;

    // Provided methods
    fn validate(
        value: Value<Self>,
    ) -> Result<Value<Self>, Self::ValidationError> { ... }
    fn value_from<T: ToValue<Self>>(t: T) -> Value<Self> { ... }
    fn value_try_from<T: TryToValue<Self>>(
        t: T,
    ) -> Result<Value<Self>, <T as TryToValue<Self>>::Error> { ... }
}
Expand description

A trait that represents an abstract schema type that can be (de)serialized as a Value.

This trait is usually implemented on a type-level empty struct, but may contain additional information about the schema type as associated constants or types. The Handle type for example contains type information about the hash algorithm, and the schema of the referenced blob.

See the value module for more information. See the BlobSchema trait for the counterpart trait for blobs.

Required Associated Types§

Source

type ValidationError

The error type returned by validate. Use () or Infallible when every bit pattern is valid.

Provided Methods§

Source

fn validate(value: Value<Self>) -> Result<Value<Self>, Self::ValidationError>

Check if the given value conforms to this schema.

Source

fn value_from<T: ToValue<Self>>(t: T) -> Value<Self>

Create a new value from a concrete Rust type. This is a convenience method that calls the ToValue trait. This method might panic if the conversion is not possible.

See the ValueSchema::value_try_from method for a conversion that returns a result.

Source

fn value_try_from<T: TryToValue<Self>>( t: T, ) -> Result<Value<Self>, <T as TryToValue<Self>>::Error>

Create a new value from a concrete Rust type. This is a convenience method that calls the TryToValue trait. This method might return an error if the conversion is not possible.

See the ValueSchema::value_from method for a conversion that always succeeds (or panics).

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.

Implementors§

Source§

impl ValueSchema for Boolean

Source§

impl ValueSchema for ED25519PublicKey

Source§

impl ValueSchema for ED25519RComponent

Source§

impl ValueSchema for ED25519SComponent

Source§

impl ValueSchema for F64

Source§

impl ValueSchema for F256BE

Source§

impl ValueSchema for F256LE

Source§

impl ValueSchema for GenId

Source§

impl ValueSchema for I256BE

Source§

impl ValueSchema for I256LE

Source§

impl ValueSchema for U256BE

Source§

impl ValueSchema for U256LE

Source§

impl ValueSchema for LineLocation

Source§

impl ValueSchema for R256BE

Source§

impl ValueSchema for R256LE

Source§

impl ValueSchema for RangeInclusiveU128

Source§

impl ValueSchema for RangeU128

Source§

impl ValueSchema for ShortString

Source§

impl ValueSchema for UnknownValue

Source§

impl ValueSchema for NsTAIInterval

Source§

impl<H> ValueSchema for Hash<H>
where H: HashProtocol,

Source§

impl<H: HashProtocol, T: BlobSchema> ValueSchema for Handle<H, T>