Why this fires¶
A namespaced derive attribute does not match the option schema declared by its
@derive_for: the option may be unknown, duplicated, missing, invalid at compile time, or
have the wrong type. Typed attributes accept named arguments only.
struct DbFieldOpts { primary: bool = false }
@derive_for(DbTable, namespace: db, field_attrs: DbFieldOpts)
fn derive_db_table(info) -> Syntax<.Items> {
return quote items { impl ${info.ref} {} }
}
struct Account {
@db(primary: "yes") // TE217: expected bool
id: int,
}Fix it¶
Use completion inside @db(...) to select a schema field, then pass a
compile-time value of the declared type.
For a TypeRef option, pass a visible type such as Team. For a
FieldRef option, pass a field such as Team.code. Strings such as
"Team" or "code" are not declaration references. Check the import and
visibility when the type is unknown, private or ambiguous.
Enum-valued options require a declared variant of the expected enum. Use
.Cascade where the schema supplies the enum type, or its explicitly
qualified spelling; an unrelated enum with the same variant name is rejected.
Collection schemas check each nested value. If an option is
#{str: [FieldRef]}, pass #{by_name: [User.name, User.id]} rather than
#{by_name: ["name", "id"]} or #{by_name: User.name}. The first alternative
has string leaves; the second omits the required list. Optional reference
elements may use nil only when the element schema allows it.