pub trait Shape: Sized {
const CLASS: Class;
const OPTIONAL: bool = false;
const IS_OBJECT: bool = false;
const CATCH_ALL: bool = false;
const KEYS: &'static [&'static str] = _;
// Required methods
fn reference() -> ShapeDef;
fn register(registry: &mut Registry);
fn build(value: &Value, path: &mut Path) -> Result<Self, Issues>;
// Provided methods
fn catch_all_shape() -> Option<ShapeDef> { ... }
fn definition() -> ShapeDef { ... }
fn register_members(registry: &mut Registry) { ... }
fn absent() -> Option<Self> { ... }
fn definitions() -> Cow<'static, Definitions> { ... }
fn build_rest(
value: &Value,
path: &mut Path,
known: &[&str],
) -> Result<Self, Issues> { ... }
fn from_json(value: &Value) -> Result<Self, Issues> { ... }
fn accepts(value: &Value) -> bool { ... }
}Expand description
A type with a shape. #[derive(Shape)] implements it from the type’s serde attributes and #[shape(...)].
Required Associated Constants§
Provided Associated Constants§
Sourceconst IS_OBJECT: bool = false
const IS_OBJECT: bool = false
Whether the type is a struct, which is what a flattened field and a newtype variant of a tagged enum must be.
Required Methods§
Sourcefn reference() -> ShapeDef
fn reference() -> ShapeDef
How a field of this type is described: a named type gives a reference to its definition, a built-in gives its shape inline.
Provided Methods§
Sourcefn catch_all_shape() -> Option<ShapeDef>
fn catch_all_shape() -> Option<ShapeDef>
The shape of those members, for a type with CATCH_ALL.
Sourcefn definition() -> ShapeDef
fn definition() -> ShapeDef
The complete shape of this type, which for a named type is what its definition holds.
Sourcefn register_members(registry: &mut Registry)
fn register_members(registry: &mut Registry)
Adds the named types this type’s fields refer to, without this type itself, for a type whose fields are merged into another object’s definition.
Sourcefn absent() -> Option<Self>
fn absent() -> Option<Self>
The value of a field of this type that is absent from its object, for a type that allows that.
Sourcefn definitions() -> Cow<'static, Definitions>
fn definitions() -> Cow<'static, Definitions>
The definitions this type is described by.
Sourcefn build_rest(
value: &Value,
path: &mut Path,
known: &[&str],
) -> Result<Self, Issues>
fn build_rest( value: &Value, path: &mut Path, known: &[&str], ) -> Result<Self, Issues>
Converts the members of an object that are not in known, for a type with CATCH_ALL.
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<T: Shape> Shape for Box<T>
impl<T: Shape> Shape for Box<T>
const CLASS: Class = T::CLASS
const IS_OBJECT: bool = T::IS_OBJECT
const KEYS: &'static [&'static str] = T::KEYS
fn reference() -> ShapeDef
fn definition() -> ShapeDef
fn register(registry: &mut Registry)
fn register_members(registry: &mut Registry)
fn build(value: &Value, path: &mut Path) -> Result<Self, Issues>
Source§impl<T: Shape> Shape for Option<T>
An absent field, and so an optional one. It is not an object type for a flattened field, whose fields would then be
optional as a group, which a shape cannot say. A field that is present is described by T alone, so null is not an
accepted spelling of absence.
impl<T: Shape> Shape for Option<T>
An absent field, and so an optional one. It is not an object type for a flattened field, whose fields would then be
optional as a group, which a shape cannot say. A field that is present is described by T alone, so null is not an
accepted spelling of absence.