Skip to main content

Registry

Struct Registry 

Source
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>

Source

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>

Source

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.

Source

pub fn flat(&self) -> &Flat

The parsed model this registry projects.

Source

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).

Source

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.

Source

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.

Source

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>

Source

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.

Source

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.

Source

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>

Source§

fn flat(&self) -> &Flat

The model.
Source§

fn reading(&self, key: &TypeKey) -> Option<TypeRef>

The reading for ty — what the frontend made of it. Read more
Source§

fn conversion(&self, dir: Direction, reading: &TypeRef) -> Option<&TypeEntry<M>>

The conversion for reading in dir, if there is one. Read more
Source§

fn callback_arg_plan(&self, key: &TypeKey) -> Option<&UnfoldPlan>

The decomposition of a callback argument type, if it has one. Read more
Source§

fn callback_arg_plans(&self) -> &HashMap<TypeKey, UnfoldPlan>

Every callback-argument decomposition, for the emitters that enumerate them rather than look one up.
Source§

fn unfold_plans(&self) -> &HashMap<Ident, UnfoldPlan>

The return decomposition of a function, if it has one.
Source§

fn error_plans(&self) -> &HashMap<Ident, UnfoldPlan>

The error-position decomposition of a fallible function.
Source§

fn decon_plans(&self) -> &HashMap<DeconId, DeconSpec>

The declaration-default decomposition behind each deconstructor.
Source§

fn crossing_keys(&self, dir: Direction) -> Vec<TypeKey>

Every type key that crosses in dir. Read more
Source§

fn reading_of(&self, ty: &Type) -> Option<TypeRef>

The reading for a spelling — identify, then look up. Read more
Source§

fn input_entry(&self, reading: &TypeRef) -> Option<&TypeEntry<M>>

Wire → rust.
Source§

fn output_entry(&self, reading: &TypeRef) -> Option<&TypeEntry<M>>

Rust → wire.
Source§

fn origin_module(&self, ident: &Ident) -> Option<Path>

The origin crate’s module path for an item, or None when unknown.
Source§

fn default_module(&self) -> Option<Path>

The default module for references with no recorded origin.
Source§

impl<M> Debug for Registry<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.