pub fn apply_companions(
files: &mut Vec<GeneratedFile>,
companions: Vec<GeneratedFile>,
)Expand description
Merge downstream Companion files into
the per-package stitcher produced by generate.
For each companion file this function locates the
PackageMod entry in files with a
matching package and appends include!("<name>"); at file scope after
buffa’s own output — at package root, alongside the owned message types,
not under __buffa::. The companion files themselves are appended to
files so that build integrations can write everything to disk in one
pass.
Call this once per build; it does not deduplicate, so a second call
with the same companions emits a second include! for each, which fails
to compile downstream with a duplicate-definition error.
name must be a bare-sibling filename — the same convention buffa uses
for its own include! calls, so it resolves relative to the stitcher
without any OUT_DIR prefix. Names must not contain / or \, must not
be empty, . or .., and must not collide with any of buffa’s own
generated filenames for the same package (<stem>.rs, <stem>.__view.rs,
etc.) — pick an unused suffix such as <stem>.__myplugin.rs. The name is
written into the include! as an escaped string literal, as buffa’s own
include paths are.
Companion files with no matching PackageMod (e.g. for a package buffa
did not generate any output for) are still appended to files but no
include! is emitted; the caller is responsible for wiring them up. If
you don’t expect orphans, check that every companion’s package appears
in files as a PackageMod after calling.
§Panics
Panics if a companion’s name contains / or \, or is empty, . or
... Every name is checked before files is changed.