Skip to main content

is_computed_attribute

Function is_computed_attribute 

pub fn is_computed_attribute(attribute: &Attribute) -> bool
Expand description

True when a single attribute’s raw text is either spelling of @computed — bare @computed or the parameterized @computed(...) form (whatever its argument, valid or not; argument-shape validation is a separate concern — see cratestack-parser’s validate_computed_field_attribute). Anchored with starts_with("@computed(") rather than the looser starts_with("@computed") deliberately: the latter would also match a hypothetical unrelated attribute merely prefixed with the same characters (e.g. @computedSomethingElse).

This is the single source of truth for “is this attribute @computed” — every consumer (codegen, client generators, migrate, wiremock, the parser’s own semantic checks) must go through this (or is_computed_field below) rather than open-coding the string comparison, so a fix here reaches every call site. A parser bug fixed by centralizing this (cratestack composite-constraint predicate bug): a local copy that only checked raw == "@computed" missed the parameterized form entirely, letting @@unique/@@id/@@index over a parameterized computed field parse cleanly and then silently drop the constraint (or narrow a primary key) at migration time.