Sails Type Registry
sails-type-registry provides portable type metadata for Sails.
It turns Rust type information into portable metadata that can be collected in
a deduplicated Registry and consumed by IDL generation and related tooling.
This crate is not a general-purpose reflection system.
What It Provides
TypeInfo: trait for exposing a Rust type as portable metadata.Registry: Named-type interner plus concrete binding cache. It stores shared named definitions and records concrete generic arguments at use sites.sails_idl_ast: portable metadata model for primitives, composites, variants, collections, generic parameters, and applied generic types.- Builder API: manual construction of named
Typevalues for explicitTypeInfoimplementations.
Derive-Based Usage
Enable the derive feature and derive TypeInfo on your types:
[]
= { = "x.y.z", = ["derive"] }
use ;
let mut registry = new;
let user_ref = registry..expect;
let user_ty = registry.get_type.unwrap;
assert_eq!;
If the crate is re-exported under another name, the derive can be pointed at that path explicitly:
use sails_type_registry as registry;
Manual TypeInfo Implementations
For synthetic or manually assembled metadata, implement TypeInfo and return a
named Type from type_def. The registry owns interning and unique-name
disambiguation.
use ;
use ;
;
let mut registry = new;
let pair_ref = registry..expect;
assert!;
When a manual named type needs to register field dependencies after caching
its own concrete TypeId, use register_named_type_with_dependencies:
Most hand-written implementations should use register_named_type; the
dependency-aware form is primarily for derive-generated recursive-safe code.
Metadata Model
Each registry entry stores:
name: human-readable type name.type_params: declared generic parameters and optional defaults.def: structural type definition.docs: captured documentation lines.annotations: captured custom metadata annotations.
Concrete bindings store per-instantiation generic arguments separately from the shared named definition.
For a generic named type, the stored definition stays abstract and field
references to declared generic parameters are represented as
TypeDecl::Generic { name }. Concrete use sites carry the applied generic
arguments:
// Stored named definition field:
Generic
// Concrete use site:
Named
This lets Wrapper<String> and Wrapper<u32> share one named Type
definition while keeping concrete arguments available for IDL export.
The metadata model covers:
- primitives
- composites and variants
- sequences, arrays, tuples, and maps
OptionandResult- generic parameter references
- applied generic types
Aliases are not represented as a separate metadata kind. The registry stores portable type descriptions, not source-level alias declarations.
Registry Naming
The derive macro owns const-generic suffixes in base names, for example
Wrapper<T, const N: usize> can register as WrapperN32 for N = 32.
The registry then handles only collision disambiguation between named types
with the same base name from different module paths. It first tries the base
name, then prepends module path segments in PascalCase, and finally appends a
numeric suffix if needed.
Features
derive: enables#[derive(TypeInfo)]viasails-type-registry-derivegprimitives: adds Gear-specific primitive support fromgprimitives