pub struct Registry<M = ()> { /* private fields */ }Expand description
Single owner of everything parsed from the prebindgen source stream.
The metadata parameter M is the language adapter’s per-converter
extra type, supplied via
crate::prebindgen::Prebindgen::Metadata. Each
TypeEntry carries one M copied in by the resolver from the
crate::prebindgen::ConverterImpl that produced it.
Adapters that don’t carry extras leave M = ().
Implementations§
Source§impl<M> Registry<M>
impl<M> Registry<M>
Sourcepub fn builder(flat: Flat) -> Result<RegistryBuilder<M>, ScanError>
pub fn builder(flat: Flat) -> Result<RegistryBuilder<M>, ScanError>
Start describing a binding over this model.
A Flat is what a registry projects, and reading captured prebindgen
output into one is FlatBuilder’s job
— so a build script says where items come from at the layer that owns
the question, and there is one such layer rather than two:
use prebindgen_registry::{Flat, Registry};
let flat = Flat::builder().source("source_ffi").build()?;
// Annotated only because nothing here resolves: in a build script `M` is
// fixed by the adapter passed to `resolve`, so no call site names it.
let registry: Registry<()> = Registry::builder(flat)?.build()?;
assert!(registry.flat().function("test_function").is_some());Several sources compose there too, including one this crate renames:
let flat = Flat::builder()
.source(flat_crate::PREBINDGEN_OUT_DIR)
.source_named(helpers::PREBINDGEN_OUT_DIR, "helpers")
.build()?;Fails on anything the language cannot express — a self receiver, an
async fn, a generic binder, a type form outside the grammar, or a
reference to a type the flat API does not declare. All of them at once, so
a source crate that needs migrating sees one list instead of one rebuild
per item. This is independent of what any binding declares: an
inexpressible item is a hard error whether or not it is ever named.
Source§impl<M> Registry<M>
impl<M> Registry<M>
Sourcepub fn expansion_plans(&self) -> &HashMap<(Ident, Ident), FoldPlan>
pub fn expansion_plans(&self) -> &HashMap<(Ident, Ident), FoldPlan>
The parameter-side fold for each (function, parameter) position.
Inherent rather than on Conversions: a fold is read when a wrapper’s
parameters are emitted, never while a conversion is being built, so no
generic caller needs it.
Sourcepub fn named_item_idents(&self) -> impl Iterator<Item = &Ident>
pub fn named_item_idents(&self) -> impl Iterator<Item = &Ident>
Every named item the model holds — functions, structs, either enum shape, consts — regardless of whether the stream carried an origin stamp.
Lives here so an adapter that needs “anything the source crate defines”
does not enumerate element kinds itself: a new kind is taught here once
instead of drifting in each adapter. An alias is deliberately absent
— see the arm below — and callers are expected to pair this with
origin_module(..).unwrap_or_else(default_module).
Sourcepub fn origin_module(&self, ident: &Ident) -> Option<Path>
pub fn origin_module(&self, ident: &Ident) -> Option<Path>
The origin crate’s module path for an item, read off the element’s
own [SourceLocation] stamp, or None when unknown — callers then fall
back to Self::default_module.
Sourcepub fn default_module(&self) -> Option<Path>
pub fn default_module(&self) -> Option<Path>
The default module for references with no recorded origin: the
first-seen item origin. None for an origin-less item-level
registry (adapters then fall back to crate). To change a module
name, override it at the source — a stream’s origin stamps
(Source::builder(dir).crate_name("myflat")) — never here: a
registry-level override could only fix ONE module, which is
incomplete with chained multi-source streams.
Sourcepub fn all_source_modules(&self) -> Vec<Path>
pub fn all_source_modules(&self) -> Vec<Path>
Module paths of every ingested source, ingestion order — e.g. for a glob import that must see all sources’ items.
Source§impl<M> Registry<M>
impl<M> Registry<M>
Sourcepub fn readings(&self, dir: Direction) -> impl Iterator<Item = &TypeRef>
pub fn readings(&self, dir: Direction) -> impl Iterator<Item = &TypeRef>
Every reading the table holds in one direction.
The adapter-facing view of the type table: a back-end asking what types crossed, and in what shape, wants the readings — not the cells they are stored in. Handing out the cells instead would make the registry’s storage part of the public API for the sake of one caller.
Sourcepub fn input_entry(&self, reading: &TypeRef) -> Option<&TypeEntry<M>>
pub fn input_entry(&self, reading: &TypeRef) -> Option<&TypeEntry<M>>
Look up the resolved input entry for reading, returning None if it
was never registered or is still unresolved. The returned entry’s
function.sig.ident is the converter’s call name; destination is
its wire form.
Takes a TypeRef for the reason the trait methods do (#284) — and this
pair matters more than they do, because an inherent method wins over
a trait method on a concrete Registry. While these took a spelling they
were a second door into the table that the trait’s signature could not
close, and every caller with a Registry in hand silently used it. The
same “second door inside the room” that hid classify behind
Registry::reading until #267.
Sourcepub fn output_entry(&self, reading: &TypeRef) -> Option<&TypeEntry<M>>
pub fn output_entry(&self, reading: &TypeRef) -> Option<&TypeEntry<M>>
Look up the resolved output entry for reading. See
Self::input_entry.
Trait Implementations§
Source§impl<M> Conversions<M> for Registry<M>
impl<M> Conversions<M> for Registry<M>
Source§fn reading(&self, key: &TypeKey) -> Option<TypeRef>
fn reading(&self, key: &TypeKey) -> Option<TypeRef>
ty — what the frontend made of it. Read moreSource§fn callback_arg_plan(&self, key: &TypeKey) -> Option<&UnfoldPlan>
fn callback_arg_plan(&self, key: &TypeKey) -> Option<&UnfoldPlan>
Source§fn callback_arg_plans(&self) -> &HashMap<TypeKey, UnfoldPlan>
fn callback_arg_plans(&self) -> &HashMap<TypeKey, UnfoldPlan>
Source§fn unfold_plans(&self) -> &HashMap<Ident, UnfoldPlan>
fn unfold_plans(&self) -> &HashMap<Ident, UnfoldPlan>
Source§fn error_plans(&self) -> &HashMap<Ident, UnfoldPlan>
fn error_plans(&self) -> &HashMap<Ident, UnfoldPlan>
Source§fn decon_plans(&self) -> &HashMap<DeconId, DeconSpec>
fn decon_plans(&self) -> &HashMap<DeconId, DeconSpec>
Source§fn crossing_keys(&self, dir: Direction) -> Vec<TypeKey>
fn crossing_keys(&self, dir: Direction) -> Vec<TypeKey>
dir. Read moreSource§fn reading_of(&self, ty: &Type) -> Option<TypeRef>
fn reading_of(&self, ty: &Type) -> Option<TypeRef>
Source§fn origin_module(&self, ident: &Ident) -> Option<Path>
fn origin_module(&self, ident: &Ident) -> Option<Path>
None when unknown.Source§fn default_module(&self) -> Option<Path>
fn default_module(&self) -> Option<Path>
Auto Trait Implementations§
impl<M = ()> !Send for Registry<M>
impl<M = ()> !Sync for Registry<M>
impl<M> Freeze for Registry<M>
impl<M> RefUnwindSafe for Registry<M>where
M: RefUnwindSafe,
impl<M> Unpin for Registry<M>where
M: Unpin,
impl<M> UnsafeUnpin for Registry<M>
impl<M> UnwindSafe for Registry<M>where
M: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more