use core::num::NonZeroU32;
use ingraph_codegen::{
index::Dedup,
model::GraphqlKind,
search::{ArmModel, MemberModel, SearchModel, SeatModel, SharedBinding, SharedBridge},
};
use crate::{
attribute::{self, set_once},
errors::Errors,
index::{DEPTH, LIMIT, list, number},
value,
};
pub(crate) mod sugar;
#[cfg(test)]
mod tests;
pub(crate) fn parse(
input: &syn::DeriveInput,
arguments: &[syn::Attribute],
) -> syn::Result<SearchModel> {
let mut errors = Errors::default();
crate::host::refuse_a_moved_option_block(&input.attrs, &mut errors);
let head = options(arguments, &mut errors);
concrete(&input.generics, &mut errors);
broadcast_is_the_wire_road(&head, &mut errors);
let fields = match named_fields(input) {
Ok(fields) => fields,
Err(terminal) => return Err(errors.seal(terminal)),
};
let members: Vec<MemberModel> = fields
.named
.iter()
.filter_map(|field| {
let name = field.ident.clone()?;
Some(member(field, name, &head.seats, &mut errors))
})
.collect();
one_producer_per_seat(&head, &members, &mut errors);
every_seat_reaches_a_member(&head, &members, &mut errors);
errors.into_result(SearchModel {
krate: head.krate.unwrap_or_else(|| syn::parse_quote!(::ingraph)),
name: input.ident.clone(),
vis: input.vis.clone(),
seats: head.seats,
dedup: head.dedup.unwrap_or_default(),
limit: head.limit,
graphql: head.graphql,
members,
})
}
#[derive(Default)]
struct Head {
krate: Option<syn::Path>,
seats: Vec<SeatModel>,
dedup: Option<Dedup>,
limit: Option<NonZeroU32>,
graphql: Option<GraphqlKind>,
graphql_at: Option<syn::Path>,
}
fn options(attrs: &[syn::Attribute], errors: &mut Errors) -> Head {
let mut head = Head::default();
let mut broadcast: Option<syn::Path> = None;
attribute::walk(attrs, errors, |meta, errors| {
if meta.path.is_ident("crate") {
match value::parse_literal::<syn::Path>(
&meta,
"`#[ingraph(crate = \"…\")]` must be a path to the `ingraph` crate, in a string literal",
) {
Ok(path) => set_once(
&mut head.krate,
path,
&meta.path,
"`crate` is declared more than once — one declaration names one crate",
errors,
),
Err(e) => refuse_value(&meta, e, errors),
}
return Ok(());
}
if meta.path.is_ident(SHARED) {
if !attribute::has_block(&meta) || attribute::empty_group(&meta) {
errors.push(attribute::named(&meta, BROADCAST_NAMES_NO_SEAT.to_owned()));
return Ok(());
}
return attribute::block(
&meta,
&mut broadcast,
"`shared(…)` is declared more than once — one recipe broadcasts one way, and two blocks \
would be two places for one seat to be named",
errors,
|inner, errors| {
seat(&inner, &mut head.seats, errors);
Ok(())
},
);
}
if meta.path.is_ident(DEDUP) {
if head.dedup.is_some() {
errors.push(syn::Error::new_spanned(
&meta.path,
"`dedup` is declared more than once — one recipe joins one way",
));
return Ok(());
}
return attribute::options(&meta, |inner| {
dedup_word(&inner, &mut head.dedup, errors);
Ok(())
});
}
if meta.path.is_ident(LIMIT) {
return number(&meta, &mut head.limit, LIMIT, HEAD, errors);
}
if meta.path.is_ident(GRAPHQL) {
if head.graphql_at.is_none() {
head.graphql_at = Some(meta.path.clone());
}
return graphql_word(&meta, &mut head.graphql, errors);
}
if meta.path.is_ident(DEPTH) {
errors.push(attribute::named(&meta, DEPTH_IS_A_MEMBERS.to_owned()));
return Ok(());
}
errors.push(attribute::unknown(
&meta,
"unknown entry in `#[ingraph::search(…)]` — it takes `shared(<seat>(type = \"…\"))` (the \
seats one question is broadcast into), `dedup(…)` (how its fused doors tell two roots \
apart), `limit = N` (how many roots its door answers when nothing asks), \
`graphql(<backend>)` (which backend dresses it) and `crate = \"…\"`. WHAT it fuses is the \
declaration's own fields, and what each member weighs is the words beside it",
&[SHARED, DEDUP, LIMIT, GRAPHQL, "crate"],
));
Ok(())
});
head
}
fn seat(inner: &syn::meta::ParseNestedMeta<'_>, seats: &mut Vec<SeatModel>, errors: &mut Errors) {
let Some(name) = inner.path.get_ident().cloned() else {
errors.push(attribute::unknown(
inner,
"a broadcast seat is named by ONE word — the word an arm writes `shared` against — and a path \
with several segments is not one. The TYPE goes inside: `<seat>(type = \"String\")`",
&[],
));
return;
};
if let Some(first) = seats.iter().find(|seat| seat.name == name) {
errors.push(attribute::named(
inner,
format!(
"`{first}` is declared more than once in `shared(…)` — one seat is one question a caller \
fills once, and a second entry would be a second type for one name",
first = first.name,
),
));
return;
}
if !attribute::has_block(inner) || attribute::empty_group(inner) {
errors.push(attribute::unknown(inner, &seat_names_no_type(&name), &[]));
return;
}
let mut ty: Option<syn::Type> = None;
let walked = inner.parse_nested_meta(|option| {
if option.path.is_ident(attribute::TYPE) {
match value::parse_literal::<syn::Type>(&option, &seat_type(&name)) {
Ok(named) => set_once(
&mut ty,
named,
&option.path,
&format!(
"`type` is declared more than once in `{name}(…)` — one seat is filled with one type"
),
errors,
),
Err(e) => refuse_value(&option, e, errors),
}
return Ok(());
}
errors.push(attribute::unknown(
&option,
&format!(
"unknown entry in `{name}(…)` — a broadcast seat names the TYPE a caller fills it with and \
nothing else. WHICH arms read it is each arm's own `shared` word, and HOW the type crosses \
into an arm's question is the word inside that one"
),
&[attribute::TYPE],
));
Ok(())
});
if let Err(e) = walked {
errors.push(e);
}
match ty {
Some(ty) => seats.push(SeatModel { name, ty }),
None => errors.push(syn::Error::new_spanned(
&inner.path,
seat_names_no_type(&name),
)),
}
}
fn member(
field: &syn::Field,
name: syn::Ident,
seats: &[SeatModel],
errors: &mut Errors,
) -> MemberModel {
let scope = format!("`{name}`");
let mut weight: Option<f64> = None;
let mut depth: Option<NonZeroU32> = None;
let mut floor: Option<syn::Path> = None;
let mut arms: Vec<ArmModel> = Vec::new();
attribute::walk(&field.attrs, errors, |meta, errors| {
if meta.path.is_ident(WEIGHT) {
ratio(&meta, &mut weight, &name, errors);
return Ok(());
}
if meta.path.is_ident(DEPTH) {
return number(&meta, &mut depth, DEPTH, &scope, errors);
}
if meta.path.is_ident(FLOOR) {
floor_word(&meta, &mut floor, &scope, errors);
return Ok(());
}
if meta.path.is_ident(TOWER) {
if !attribute::has_block(&meta) || attribute::empty_group(&meta) {
errors.push(attribute::named(&meta, tower_names_no_arm(&name)));
return Ok(());
}
return meta.parse_nested_meta(|inner| {
arm(&inner, &mut arms, seats, &name, errors);
Ok(())
});
}
errors.push(attribute::unknown(
&meta,
"unknown entry in `#[ingraph(…)]` on a member — a member takes `weight = 1.0` (its \
coefficient in the fold), `depth = N` (how deep its route is asked), `floor = \"…\"` (the \
const its read is floored at) and `tower(<arm>(type = \"…\"))` (the towers its question has \
arms for, one entry each). Its NAME is the field's own and the INDEX it reads is the field's \
type, so neither has a word",
&[WEIGHT, DEPTH, FLOOR, TOWER],
));
Ok(())
});
MemberModel {
field: name,
ty: field.ty.clone(),
weight,
depth,
floor,
arms,
}
}
fn arm(
inner: &syn::meta::ParseNestedMeta<'_>,
arms: &mut Vec<ArmModel>,
seats: &[SeatModel],
member: &syn::Ident,
errors: &mut Errors,
) {
let Some(name) = inner.path.get_ident().cloned() else {
errors.push(attribute::unknown(
inner,
"an arm is named by ONE word — the variant this member's question mints, and the seat an arm \
may read — and a path with several segments is not one. The TOWER goes inside: \
`<arm>(type = \"path::To::Tower\")`",
&[],
));
return;
};
if arms.iter().any(|bound| bound.name == name) {
errors.push(attribute::named(
inner,
format!(
"`{name}` is bound more than once on `{member}` — an arm's name is the variant it mints in \
this member's own question, and a second entry would be two arms with one name. Two \
MEMBERS may each carry an arm called `{name}`; one member may not"
),
));
return;
}
if !attribute::has_block(inner) || attribute::empty_group(inner) {
errors.push(attribute::unknown(inner, &arm_names_no_tower(&name), &[]));
return;
}
let mut tower: Option<syn::Type> = None;
let mut floor: Option<syn::Path> = None;
let mut written: Option<(SharedBridge, syn::Path)> = None;
let scope = format!("`{name}(…)` on `{member}`");
let walked = inner.parse_nested_meta(|option| {
if option.path.is_ident(attribute::TYPE) {
match value::parse_literal::<syn::Type>(&option, &arm_type(&name)) {
Ok(named) => set_once(
&mut tower,
named,
&option.path,
&format!("`type` is declared more than once in {scope} — one arm is walked by one tower"),
errors,
),
Err(e) => refuse_value(&option, e, errors),
}
return Ok(());
}
if option.path.is_ident(SHARED) {
shared_word(&option, &mut written, &scope, errors);
return Ok(());
}
if option.path.is_ident(FLOOR) {
floor_word(&option, &mut floor, &scope, errors);
return Ok(());
}
errors.push(attribute::unknown(
&option,
&format!(
"unknown entry in {scope} — an arm takes `type = \"…\"` (the tower that walks it), \
`shared` (that it reads the recipe's broadcast, and how the seat crosses) and \
`floor = \"…\"` (the const its read is floored at). What the tower is ASKED and what it \
ANSWERS are the tower's own declaration, read where the compiler can resolve them"
),
&[attribute::TYPE, SHARED, FLOOR],
));
Ok(())
});
if let Err(e) = walked {
errors.push(e);
}
let Some(tower) = tower else {
errors.push(syn::Error::new_spanned(
&inner.path,
arm_names_no_tower(&name),
));
return;
};
let shared = written.and_then(|(bridge, at)| {
resolve(&name, seats, &at, errors).map(|seat| SharedBinding { seat, bridge })
});
arms.push(ArmModel {
name,
tower,
shared,
floor,
});
}
fn shared_word(
option: &syn::meta::ParseNestedMeta<'_>,
written: &mut Option<(SharedBridge, syn::Path)>,
scope: &str,
errors: &mut Errors,
) {
if attribute::has_value(option) {
errors.push(attribute::named(
option,
format!(
"`shared` in {scope} is a word rather than a value — write it bare for the total crossing, \
`shared(try)` for the fallible one, or `shared(with = \"path::to::hook\")` and \
`shared(try_with = \"…\")` for a function of your own"
),
));
return;
}
if written.is_some() {
errors.push(attribute::named(
option,
format!(
"`shared` is declared more than once in {scope} — one arm crosses from one seat one way, \
and the four spellings fill the same seat"
),
));
return;
}
if !attribute::has_block(option) || attribute::empty_group(option) {
attribute::skip_entry(option);
*written = Some((SharedBridge::Total, option.path.clone()));
return;
}
let mut bridge: Option<SharedBridge> = None;
let walked = option.parse_nested_meta(|word| {
let chosen = if word.path.is_ident(TRY) {
if attribute::has_value(&word) || attribute::has_block(&word) {
errors.push(attribute::named(&word, TRY_IS_BARE.to_owned()));
return Ok(());
}
SharedBridge::Fallible
} else if word.path.is_ident(WITH) || word.path.is_ident(TRY_WITH) {
let fallible = word.path.is_ident(TRY_WITH);
match value::parse_literal::<syn::Path>(&word, &hook_path(fallible)) {
Ok(hook) if fallible => SharedBridge::FallibleHook(hook),
Ok(hook) => SharedBridge::Hook(hook),
Err(e) => {
refuse_value(&word, e, errors);
return Ok(());
}
}
} else {
errors.push(attribute::unknown(
&word,
&format!(
"unknown entry in `shared(…)` in {scope} — it names HOW the seat crosses into this arm's \
question, and nothing else: `try` for the fallible conversion, `with = \"…\"` and \
`try_with = \"…\"` for a function of your own. A bare `shared` is the total crossing"
),
&[TRY, WITH, TRY_WITH],
));
return Ok(());
};
if let Some(first) = &bridge {
errors.push(syn::Error::new_spanned(
&word.path,
format!(
"`shared(…)` names ONE crossing and `{first}` was already named — the word decides which \
conversion this arm's question is DEMANDED through, and a declaration that asks for two \
is asking for neither",
first = first.word(),
),
));
return Ok(());
}
bridge = Some(chosen);
Ok(())
});
if let Err(e) = walked {
errors.push(e);
}
*written = Some((bridge.unwrap_or(SharedBridge::Total), option.path.clone()));
}
fn resolve(
arm: &syn::Ident,
seats: &[SeatModel],
at: &syn::Path,
errors: &mut Errors,
) -> Option<syn::Ident> {
if let Some(seat) = seats.iter().find(|seat| seat.name == *arm) {
return Some(seat.name.clone());
}
if let [only] = seats {
return Some(only.name.clone());
}
if seats.is_empty() {
errors.push(syn::Error::new_spanned(
at,
format!(
"`{arm}` reads a broadcast this recipe does not declare — `shared` says the question for \
this arm is the one the whole recipe was asked, and the seats that question is filled at \
are the head's own `shared(…)`. Write `#[ingraph::search(shared({arm}(type = \"…\")))]`, \
or take the word off and let this arm be asked its own question"
),
));
return None;
}
let names: Vec<String> = seats.iter().map(|seat| seat.name.to_string()).collect();
let spelled: Vec<&str> = names.iter().map(String::as_str).collect();
errors.push(syn::Error::new_spanned(
at,
format!(
"`{arm}` reads a broadcast seat this recipe does not declare — the seats are {names}, and a \
seat feeds the arms that share its NAME. This recipe declares several, so there is no sole \
seat for an unmatched arm to fall back to: rename the arm to the seat it reads, or add \
`{arm}(type = \"…\")` to the head's `shared(…)`{near}",
names = list(&spelled),
near = crate::suggest::did_you_mean(&arm.to_string(), &spelled),
),
));
None
}
fn floor_word(
meta: &syn::meta::ParseNestedMeta<'_>,
slot: &mut Option<syn::Path>,
scope: &str,
errors: &mut Errors,
) {
if attribute::has_block(meta) {
errors.push(attribute::named(meta, LEG_FLOOR.to_owned()));
return;
}
match value::parse_literal::<syn::Path>(meta, FLOOR_CONST) {
Ok(path) => set_once(
slot,
path,
&meta.path,
&format!("`floor` is declared more than once in {scope} — one read is floored at one const"),
errors,
),
Err(e) => refuse_value(meta, e, errors),
}
}
fn ratio(
meta: &syn::meta::ParseNestedMeta<'_>,
slot: &mut Option<f64>,
member: &syn::Ident,
errors: &mut Errors,
) {
let written = match value::float(meta, WEIGHT_RATIO) {
Ok(written) => written,
Err(refusal) => {
refuse_value(meta, refusal, errors);
return;
}
};
let Ok(ratio) = written.base10_parse::<f64>() else {
errors.push(syn::Error::new_spanned(&written, WEIGHT_RATIO));
return;
};
if !ratio.is_finite() {
errors.push(syn::Error::new_spanned(
&written,
format!(
"`weight` on `{member}` is past what a coefficient can be — it MULTIPLIES every term this \
member contributes to the fold, so a number with no finite value makes every one of them \
the same number and the fold's order an accident"
),
));
return;
}
set_once(
slot,
ratio,
&meta.path,
&format!("`weight` is declared more than once on `{member}` — one member, one coefficient"),
errors,
);
}
fn dedup_word(
inner: &syn::meta::ParseNestedMeta<'_>,
dedup: &mut Option<Dedup>,
errors: &mut Errors,
) {
let Some(word) = inner.path.get_ident() else {
errors.push(attribute::unknown(
inner,
&format!(
"`dedup(…)` takes ONE word — {words} — and a path with several segments is not one",
words = list(&Dedup::WORDS),
),
&[],
));
return;
};
let chosen = if word == Dedup::Hash.as_str() {
Dedup::Hash
} else if word == Dedup::Eq.as_str() {
Dedup::Eq
} else {
errors.push(syn::Error::new_spanned(
word,
format!(
"`{word}` is not a dedup mechanism — the words are {words}. `hash` compares keys by hashing \
them and asks the key for `Hash + Eq`; `eq` walks a seen-list comparing every field and \
asks only for `PartialEq`, which is the escape for a key that cannot hash. The vocabulary \
is the framework's, so a mechanism it does not implement is not a word here{near}",
words = list(&Dedup::WORDS),
near = crate::suggest::did_you_mean(&word.to_string(), Dedup::WORDS),
),
));
return;
};
if let Some(first) = dedup {
errors.push(syn::Error::new_spanned(
word,
format!(
"`dedup(…)` names ONE mechanism and `{first}` was already named — the word is a BOUND on \
the key this recipe's members are fused at, and a declaration that asks for both is asking \
for neither",
first = first.as_str(),
),
));
return;
}
*dedup = Some(chosen);
}
fn refuse_value(meta: &syn::meta::ParseNestedMeta<'_>, error: syn::Error, errors: &mut Errors) {
errors.push(error);
attribute::skip_entry(meta);
}
fn named_fields(input: &syn::DeriveInput) -> syn::Result<&syn::FieldsNamed> {
match &input.data {
syn::Data::Struct(data) => match &data.fields {
syn::Fields::Named(named) if !named.named.is_empty() => Ok(named),
syn::Fields::Named(named) => Err(syn::Error::new_spanned(named, EMPTY_RECIPE)),
syn::Fields::Unit => Err(syn::Error::new_spanned(&input.ident, EMPTY_RECIPE)),
syn::Fields::Unnamed(unnamed) => Err(syn::Error::new_spanned(unnamed, POSITIONAL_MEMBERS)),
},
syn::Data::Enum(_) | syn::Data::Union(_) => Err(syn::Error::new_spanned(
&input.ident,
"`#[ingraph::search]` supports structs only — a recipe's FIELDS are the members it fuses, all \
of them at once, and variants are a choice between things rather than a list of them",
)),
}
}
fn concrete(generics: &syn::Generics, errors: &mut Errors) {
const WHY: &str = "a search recipe takes no generic parameter — the emission binds ONE set of \
members and towers over ONE declaration, and a parameter is not a type until \
it is substituted, so a generic recipe would prove its bindings for nobody";
if !generics.params.is_empty() {
errors.push(syn::Error::new_spanned(generics, WHY));
} else if let Some(clause) = &generics.where_clause {
errors.push(syn::Error::new_spanned(clause, WHY));
}
}
fn broadcast_is_the_wire_road(head: &Head, errors: &mut Errors) {
let (Some(at), true) = (head.graphql_at.as_ref(), head.graphql.is_some()) else {
return;
};
if !head.seats.is_empty() {
return;
}
errors.push(syn::Error::new_spanned(
at,
"`graphql(…)` publishes a field asked with a broadcast, and this recipe declares no \
`shared(…)` seat — so a client would have nothing to ask it with. Write a seat — \
`shared(<seat>(type = \"…\"))`, or several, which publishes them as a choice — or drop the \
block: a recipe with no wire face keeps its whole Rust surface, the record, the packages, the \
evidence and the door",
));
}
fn one_producer_per_seat(head: &Head, members: &[MemberModel], errors: &mut Errors) {
if head.graphql.is_none() {
return;
}
for member in members {
let mut producers: Vec<(&syn::Ident, &syn::Ident)> = Vec::new();
for arm in &member.arms {
let Some(shared) = arm.shared.as_ref() else {
continue;
};
let bought = producers
.iter()
.find(|(seat, _)| **seat == shared.seat)
.copied();
let Some((seat, first)) = bought else {
producers.push((&shared.seat, &arm.name));
continue;
};
errors.push(syn::Error::new(
arm.name.span(),
format!(
"`{member}` is published, so its question is produced by ONE bound tower per seat — and \
`{first}` and `{second}` both read this recipe's `{seat}` broadcast. A resolver runs the \
arm's tower and crosses what it ANSWERS into `{member}`'s question, and two answers \
cannot both be that question. Keep one arm on `{seat}` here and give the other its own \
member or its own seat, or drop the `graphql(…)` block: an undressed recipe keeps every \
arm, its record and its options rows",
member = member.field,
second = arm.name,
),
));
}
}
}
fn every_seat_reaches_a_member(head: &Head, members: &[MemberModel], errors: &mut Errors) {
if head.graphql.is_none() {
return;
}
for seat in &head.seats {
if members.iter().any(|member| reaches(member, &seat.name)) {
continue;
}
errors.push(syn::Error::new(
seat.name.span(),
format!(
"`{seat}` is a seat no member reaches — every member of this published recipe binds a \
`shared` arm, and none of them binds one on `{seat}`. A client fills exactly one seat, so \
this one is a request that would walk no tower, ask no engine and fuse nothing. Bind an \
arm to it — `tower({seat}(type = \"path::To::Tower\", shared))` on the member that answers \
it — or take it out of `shared(…)`",
seat = seat.name,
),
));
}
}
fn reaches(member: &MemberModel, seat: &syn::Ident) -> bool {
let mut bought = member.arms.iter().filter_map(|arm| arm.shared.as_ref());
let Some(first) = bought.next() else {
return true;
};
first.seat == *seat || bought.any(|shared| shared.seat == *seat)
}
const SHARED: &str = "shared";
const DEDUP: &str = "dedup";
const GRAPHQL: &str = "graphql";
const WEIGHT: &str = "weight";
const FLOOR: &str = "floor";
const TOWER: &str = "tower";
const TRY: &str = "try";
const WITH: &str = "with";
const TRY_WITH: &str = "try_with";
const HEAD: &str = "this recipe's head";
fn graphql_word(
meta: &syn::meta::ParseNestedMeta<'_>,
graphql: &mut Option<GraphqlKind>,
errors: &mut Errors,
) -> syn::Result<()> {
if graphql.is_some() {
errors.push(syn::Error::new_spanned(
&meta.path,
"`graphql(…)` is declared more than once — one block names every backend that dresses this \
recipe, and a second would be a second place for one fact",
));
attribute::skip_entry(meta);
return Ok(());
}
let mut named: Option<GraphqlKind> = None;
let walked = attribute::options(meta, |inner| {
let Some(kind) = crate::parse::graphql_kind(&inner.path) else {
errors.push(attribute::unknown(
&inner,
&format!(
"unknown backend in `graphql(…)` — this framework renders through {list}, and a word \
naming none of them names no skin",
list = list(&GraphqlKind::ALL.map(GraphqlKind::as_str)),
),
&GraphqlKind::ALL.map(GraphqlKind::as_str),
));
return Ok(());
};
if named == Some(kind) {
errors.push(syn::Error::new_spanned(
&inner.path,
format!(
"`{kind}` is declared more than once in `graphql(…)` — a backend has ONE skin and a \
second word could only re-describe it",
kind = kind.as_str(),
),
));
attribute::skip_entry(&inner);
return Ok(());
}
named = Some(kind);
Ok(())
});
if named.is_none() {
errors.push(syn::Error::new_spanned(
&meta.path,
format!(
"`graphql` names no backend, and a wire face is one backend's impls — write \
`graphql({first})`. Without the word this recipe still emits its WHOLE Rust surface: the \
record, the packages, the evidence and the door are all there, and what the block adds is \
a schema over them",
first = GraphqlKind::ALL[0].as_str(),
),
));
return walked;
}
*graphql = named;
walked
}
const BROADCAST_NAMES_NO_SEAT: &str = "`shared` at the RECIPE names the seats one question is \
broadcast into — write `shared(text(type = \"String\"))`. The BARE word is an ARM's, where it \
says that arm's question is the one the whole recipe was asked; at the head there is nothing for \
a seatless `shared` to declare";
fn tower_names_no_arm(member: &syn::Ident) -> String {
format!(
"`tower` names the arms `{member}` binds — write `tower(text(type = \"path::To::Tower\"))`. A \
member that binds NO tower writes no `tower(…)` at all, so an empty one is a word that decided \
nothing rather than a member declaring it has no arms"
)
}
fn seat_names_no_type(name: &syn::Ident) -> String {
format!(
"`{name}` names no type — a broadcast seat is a question a CALLER fills once for the whole \
recipe, so write `{name}(type = \"path::to::Question\")`. A seat with no type is a name for a \
question nobody can ask"
)
}
fn seat_type(name: &syn::Ident) -> String {
format!(
"`{name}` names the TYPE a caller fills this seat with — quoted, because the word names a type \
this declaration cannot resolve and the compiler resolves where the expansion lands"
)
}
fn arm_names_no_tower(name: &syn::Ident) -> String {
format!(
"`{name}` names no tower — an arm IS a bound tower, so write \
`{name}(type = \"path::To::Tower\")`. What that tower is asked and what it answers are its own \
declaration's, read through it rather than restated here; a member that binds none simply \
writes no `tower(…)` at all"
)
}
fn arm_type(name: &syn::Ident) -> String {
format!(
"`{name}` names the TOWER that walks this arm — quoted, because the word names a type this \
declaration cannot resolve and the compiler resolves where the expansion lands"
)
}
fn hook_path(fallible: bool) -> String {
let word = if fallible { TRY_WITH } else { WITH };
format!(
"`{word}` names a FUNCTION of yours that turns the broadcast seat into this arm's question — as \
a path in a string literal, because it names an item this declaration cannot resolve"
)
}
const FLOOR_CONST: &str = "`floor` names a CONST, as a path in a string literal — \
`floor = \"crate::floors::SEM_TEXT\"`. A literal is refused rather than converted: a floor is a \
value in the ENGINE's own currency, which is an open type this framework never sees, so there is \
nothing here for a number to be parsed into. A const is one its own crate already built";
const LEG_FLOOR: &str = "`floor(…)` would name a floor per LEG, and a recipe has no word for one. A \
member's legs are its own declaration's — their names, their engines and their currencies are \
written there — so a recipe pointing at one would be reaching inside a declaration it cannot \
see. A recipe floors what it can name: `floor = \"…\"` on the MEMBER, and `floor = \"…\"` inside \
an arm. A per-leg floor is a REQUEST's, where the leg is already addressed";
const WEIGHT_RATIO: &str = "`weight` is a RATIO, as a plain decimal — `weight = 2.0`. It is the \
coefficient this member takes in the fold, so `2` is refused for the SPELLING rather than the \
value: one shape for one number is one thing every later reader has to remember";
const TRY_IS_BARE: &str = "`try` is a bare word here — it names WHICH conversion this arm's \
question is demanded through, and the conversion is the author's own impl, so there is nothing \
to configure. A function of yours goes in `try_with = \"path::to::hook\"`";
const DEPTH_IS_A_MEMBERS: &str = "`depth` is a MEMBER's number here — a recipe asks each member its \
own way, so the word goes on the field: `#[ingraph(depth = 50)] subs: Subs`. What the head takes \
is `limit`, which is how many ROOTS the fused door answers with";
const EMPTY_RECIPE: &str = "a recipe lists no member — its FIELDS are what it fuses, so one with \
none has nothing to ask, nothing to fuse and no answer to shape";
const POSITIONAL_MEMBERS: &str = "a recipe must be a struct with NAMED fields — a field's name is \
the member's name, which is one name serving the fold, the evidence variant and the schema row \
alike, and a positional field has none of them";