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§
Sourcetype ValidationError
type ValidationError
The error type returned by validate.
Use () or Infallible when every bit pattern is valid.
Provided Methods§
Sourcefn validate(value: Value<Self>) -> Result<Value<Self>, Self::ValidationError>
fn validate(value: Value<Self>) -> Result<Value<Self>, Self::ValidationError>
Check if the given value conforms to this schema.
Sourcefn value_from<T: ToValue<Self>>(t: T) -> Value<Self>
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.
Sourcefn value_try_from<T: TryToValue<Self>>(
t: T,
) -> Result<Value<Self>, <T as TryToValue<Self>>::Error>
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.