#[non_exhaustive]pub struct TypeDescriptor {
pub id: TypeId,
pub name: String,
pub version: String,
pub canonical_collection: Option<String>,
pub validate_json: JsonValidatorFn,
pub proto3_zero_fn: Proto3ZeroFn,
pub fields: Vec<FieldDescriptor>,
}Expand description
Descriptor for one known type. Registries hand back references to these so consumers can use them as a stable handle through their own data flow.
#[non_exhaustive]: additional fields (renderer hints, deprecation
markers, etc.) can be added in follow-on commits without breaking
external consumers. Construct externally via TypeDescriptor::new
plus direct field assignment for the optional fields.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: TypeIdCanonical, stable identifier.
name: StringHuman-readable display name (without the proto path).
version: StringVersion label (e.g. "v1"). Convention; not parsed.
canonical_collection: Option<String>Conventional collection where documents of this type live.
None for types that aren’t associated with a single collection
by convention. Consumers MAY override this at the registry-build
layer for deployment-specific collection layouts.
validate_json: JsonValidatorFnValidator: JSON value → typed message → field-level validate.
proto3_zero_fn: Proto3ZeroFnProto3 wire-zero JSON supplier (peat#953). Returns the canonical proto3 zero JSON for this type — every field populated with its proto3 default (string → “”, numeric → 0/0.0, bool → false, enum → first variant, repeated → [], optional message → null).
Driven by the prost-generated Default impl on the underlying
message struct, so the value cannot drift from the proto3 field
list — consumers always get the current canonical zero shape as
the schema evolves.
Defaulted to default_proto3_zero (returns {}) by
Self::new so external callers that haven’t wired in a
proto3-aware zero supplier fall back to a safe empty-object
shape; descriptors registered by
BuiltinRegistry::with_peat_schema_types are built by the
crate’s private descriptors module helpers, which set this
field explicitly via the prost-generated Default of each
type. (Plain prose rather than an intra-doc link on the
helpers — the descriptors module is private, so a
[\mod@descriptors`]link would failrustdoc::private-intra-doc-linksundercargo doc – -D warnings`.)
fields: Vec<FieldDescriptor>Fields in canonical display order, with rendering hints. Renderer-side downstream consumers iterate this list to produce typed output. Empty for types that don’t yet have field metadata authored.
Implementations§
Source§impl TypeDescriptor
impl TypeDescriptor
Sourcepub fn new(
id: TypeId,
name: impl Into<String>,
version: impl Into<String>,
validate_json: JsonValidatorFn,
) -> Self
pub fn new( id: TypeId, name: impl Into<String>, version: impl Into<String>, validate_json: JsonValidatorFn, ) -> Self
Construct a TypeDescriptor with the required fields. Optional
fields (canonical_collection, proto3_zero_fn, fields)
default to empty / no-op; callers set them via direct field
assignment after construction.
Use this from external crates that register their own types —
direct struct-literal construction is reserved for peat-schema
itself so future field additions stay non-breaking.
Sourcepub fn proto3_zero(&self) -> Value
pub fn proto3_zero(&self) -> Value
Return the canonical proto3 wire-zero JSON for this type (peat#953).
Every field of the proto3 message is populated with its zero
value, exactly as the prost-generated Default::default() for
the underlying struct would produce after serde_json::to_value.
Consumers that need to fill in a partial user payload before
strict prost-derived Deserialize (e.g. peat-cli’s
apply_proto3_defaults for partial --set payloads, or any
SDK that needs to construct a baseline document programmatically)
merge user-supplied fields on top of this value.
Round-trips through this type’s Deserialize impl by
construction: the value is serde_json::to_value(<T>::default())
where <T> already implements both Default (prost) and
Serialize (peat-schema build script), so the deserialise of
the wire-form of a valid in-memory instance is always a valid
in-memory instance.
§Example
use peat_schema::type_registry::{BuiltinRegistry, TypeRegistry};
let registry = BuiltinRegistry::with_peat_schema_types();
let desc = registry.for_collection("capabilities").unwrap();
let zero = desc.proto3_zero();
// Every field of `Capability` is present at its proto3 zero.
assert!(zero.is_object());Trait Implementations§
Source§impl Clone for TypeDescriptor
impl Clone for TypeDescriptor
Source§fn clone(&self) -> TypeDescriptor
fn clone(&self) -> TypeDescriptor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more