#[fields]Expand description
Declare a FIELD FRAGMENT — a group of fields several declarations hold, written once.
#[ingraph::fields(record, entity, graphql)]
pub struct Dimensions {
#[ingraph(copy)]
width: u32,
#[ingraph(copy)]
height: u32,
}§A fragment is HELD, and every absence follows from that
It is the ladder’s bottom rung — 公用字段抽取 — and it is not a node. A holder declares one as an ordinary field, its columns land in the holder’s row, and its wire presence is a fragment of the holder’s object. So this derive is FAMILY-LESS, and none of the absences is an era rule waiting to lift:
| absent | because |
|---|---|
Identifiable | it bears no id — that is what the tier MEANS |
Transformer | that face is a key and the two address types beside it |
Graphql | a wire face is a queryable ROOT, and a fragment is a fragment |
| every storage | its columns are the HOLDER’s row |
A group of fields that does bear an identity is an entity, and one that holds rows besides is
a record. Both refusals name both rungs, so a migrating author reads which one they wanted.
§The word was entity, and the rename is the ladder’s
The tier’s own doc said no stable identity is what the tier means while entity names an
identity-bearing thing everywhere else in this framework. The code moved WHOLE; only the word
changed, and entity now names the rung it always described.
§ACTIVATION, which is required
A fragment is HELD, so what it has to ANSWER is whatever the holding kind asks — and the kinds ask different things. Three words say who asks, and a declaration that writes none of them is a named refusal:
| word | activates |
|---|---|
record[(<db>, …)] | the STORAGE faces — the width, the bind, the read, the keyset, the comparison |
entity | the READ faces — the predicate and the two marker rows a holder resolves a slot through |
graphql[(…)] | the WIRE face — the object, its crossing, and the filter’s input-object registration |
The first two are HOST KINDS, and a record activates the read faces too — its own filter being that same predicate. The third is not a host kind: it says the declaration has a face a client can reach at all. There is no shorthand for both host kinds; write both. The accessor family is the tier’s own and is emitted either way.
record(sqlite, postgres) is the record head’s own store words one namespace in: it names the
dialects this fragment is BUILT for and claims no table, the table being the holder’s. entity
is BARE — entity-hosting has nothing to configure yet, and entity(…) says so by name.
graphql(rename = "…", filter(rename = "…")) names the OBJECT and the BASE the filter’s input
objects compose off — filter(rename = "Dim") publishing DimFilter beside DimColumnFilter,
per the twin law.
§Attributes
On the struct, beside the three activations:
crate = "path::to::ingraph"— whereingraphlives, exactly asrecord’s. Present because the expansion spends it: aVec<_>field is handed back throughproject::Repeatedand anOption<_>throughproject::Optional.remote = "path::To::Type"— the FOREIGN TYPE this fragment wraps. See The rewrite mode below.builder(…)— the wrapped type’s construction protocol, which the storage face’s hydration spends.cursor[(…)]— this fragment is a paging position in its own declared order. It needsrecord: both halves of what spends the assertion need rows to walk.
Every block a node writes — key(…), lineage(…), a store word, table, fulltext(…),
vector(…), blob(…) — is refused BY NAME, each message saying what a fragment has instead.
On a field: the three projection words (copy, repeated, optional), builder(…), the
host-kind namespace record(…) and the wire face’s own graphql(rename = "…"). What a field
says to a host kind goes INSIDE that kind’s namespace, which is what keeps one ident from meaning
two things at two seats — record(skip), record(skip(default = "…")), record(flatten) and
the per-dialect claims are the record field seat’s own words, letter for letter one level in.
The labels and the wire legs are still declared ONCE here and inherited by every holder; what
reads that inheritance has not arrived, so those are a named refuse-until rather than a fact
parsed into a model nothing spends. id is refused separately and permanently, by the tier’s own
definition.
A field’s #[cfg] is SERVED, family-wide: it takes the accessor, the segment, the bind, the read,
the filter seat and the place on the wire face, all together. Two things it cannot reach are
refused by name — a where predicate takes no attribute, and a cursor fragment’s key is every
declared field, so a member that could vanish would page by a different key.
§The rewrite mode
#[ingraph::fields(record, entity, remote = "mediaframe::Dimensions")]
pub struct Dimensions {
/// The width in pixels.
width: u32,
height: u32,
}The fields written above are a MANIFEST — the shape of a type another crate owns, restated so
this framework can read it — and the item the compiler sees is
#[repr(transparent)] pub struct Dimensions(mediaframe::Dimensions);. The orphan rule is why
the mode exists: a type another crate owns cannot be given this framework’s faces where it is
declared, and a wrapper is the position where it can.
fields is the FOURTH declaration to take the word and the first with NO IDENTITY SEAT. Each
manifest field gets ONE reader — width(&self) -> u32, reading self.0.width() and crossing it
by Into — with the field’s own doc comments migrated onto it, since the rewrite deletes the
field that held them. There are no mutators (a remote’s fields are its own), no const reader
(a foreign accessor is not this macro’s to declare const), and no borrow reader anywhere: a
record’s rewrite borrows its id column because this framework’s identity seats borrow, and a
fragment has no id.
Beside the readers come Deref, DerefMut, AsRef, AsMut, Borrow, BorrowMut and From
in both directions, so the wrapper is usable where the wrapped type was and inherits its methods.
The macro OWNS the #[repr(…)]; an author’s own is refused. Every other item attribute —
#[derive(…)], #[cfg], doc comments — is forwarded onto the wrapper verbatim.
§What it emits
One inherent impl: the accessor family for every field, and the mutator pair beside each. A record withholds the mutators from the fields that bear identity; a fragment has no such field, which is why every one of its fields takes both.
Beside it are the FACES the activations asked for — the column width, the bind, the read, the
keyset, the comparison, the predicate, and the fragment’s own output object with the predicate’s
input face. There is still no constructor, no Default, no identity, no storage of its own and
no queryable root: what a fragment answers are questions its holder was already asking.
§Refusals
The declaration’s SHAPE is the fragment, so each part of it is checked here rather than left to
fail inside the expansion: a non-struct, a positional or unit struct, any generic parameter, and
a struct with no field at all — the tier exists to declare fields a holder inherits, so a
declaration with none has nothing to inherit. Two more are about the EMISSION: a field whose
name takes the framework’s __name__ shape, and two fields reaching one method name.