pub struct CustomAnnotation {
pub name: String,
pub value: String,
pub line: usize,
pub suggested_keyword: Option<String>,
}Expand description
A custom (non-native) annotation captured verbatim from the SQL source.
Scythe parses its known annotations (@name, @returns, @param, @nullable,
@nonnull, @json, @optional, @group_by, @deprecated) into typed fields.
Any other -- @<name> <value> line is captured here as an opaque triple and
exposed to crate consumers, who can layer their own annotation vocabulary on
top of scythe without coupling scythe to their domain.
That escape hatch means an unrecognised annotation can never be a hard parse
error – rejecting it outright would break every legitimate consumer-defined
annotation (e.g. @http, @http_auth) alongside the typos it was meant to
catch. suggested_keyword is the softer signal:
it flags names close enough to a known keyword to plausibly be a typo of it
(@nullible for @nullable, @optionall for @optional), for a caller to
surface as a warning without duplicating scythe’s keyword list or edit-distance
logic. See #152 – before this field existed, a misspelled @nullable /
@nonnull / @optional was captured here and never inspected by anything,
so scythe generate, scythe check and scythe lint all reported success
while the override it named was silently discarded.
Fields§
§name: StringAnnotation name, lowercased, without the leading @ (e.g. http, http_param).
value: StringEverything after the name on the line, trimmed. Empty if the annotation had no value.
line: usize1-based line number within the query SQL, for diagnostics.
suggested_keyword: Option<String>A known annotation keyword within edit distance 2 of name, if any – e.g.
Some("nullable".to_string()) for nullible. None when name is not close to
any known keyword (the common case: a genuine consumer-defined annotation). An owned
String rather than &'static str so the type stays trivially Deserialize (a
borrowed-forever &'static str field cannot round-trip through an arbitrary
deserializer’s input lifetime).