Skip to content

Commit 705a230

Browse files
committed
registry made more universal
1 parent 3448eae commit 705a230

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

prebindgen-ext/src/core/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Core: language-agnostic primitives for the Registry-based pipeline.
22
//!
3-
//! Public entry point: [`registry::Registry::from_source`] scans a
4-
//! `prebindgen::Source` into a flat type table; [`registry::Registry::write_rust`]
3+
//! Public entry point: [`registry::Registry::from_items`] scans a stream
4+
//! of `(syn::Item, SourceLocation)` into a flat type table;
5+
//! [`registry::Registry::write_rust`]
56
//! resolves every required type using the configured
67
//! [`prebindgen_ext::PrebindgenExt`] and emits the bindings file. Kotlin
78
//! emission for the JNI back-end lives in `crate::jni::JniExt::write_kotlin`.

prebindgen-ext/src/core/registry.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use std::collections::{HashMap, HashSet};
1717
use std::fmt;
1818

19-
use prebindgen::{Source, SourceLocation};
19+
use prebindgen::SourceLocation;
2020
use quote::ToTokens;
2121

2222
use crate::core::niches::Niches;
@@ -233,12 +233,20 @@ impl From<crate::core::write::WriteError> for WriteRustError {
233233
}
234234

235235
impl Registry {
236-
/// Construct a `Registry` by scanning a `prebindgen::Source`.
237-
pub fn from_source(source: &Source) -> Result<Self, ScanError> {
236+
/// Construct a `Registry` by scanning a stream of source items.
237+
///
238+
/// Callers feed any `(syn::Item, SourceLocation)` iterator — typically
239+
/// `source.items_all()`, `source.items_except_groups(...)`, or a
240+
/// hand-rolled filter chain — so item-level selection happens upstream
241+
/// of the registry rather than inside it.
242+
pub fn from_items<I>(items: I) -> Result<Self, ScanError>
243+
where
244+
I: IntoIterator<Item = (syn::Item, SourceLocation)>,
245+
{
238246
let mut registry = Registry::default();
239247

240248
// Phase 1 — index all items.
241-
for (item, loc) in source.items_all() {
249+
for (item, loc) in items {
242250
registry.index_item(item, loc)?;
243251
}
244252

prebindgen-ext/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Registry-based universal converter pipeline for `#[prebindgen]` items.
22
//!
33
//! Pipeline:
4-
//! 1. [`core::Registry::from_source`] scans a `prebindgen::Source`.
4+
//! 1. [`core::Registry::from_items`] scans a stream of
5+
//! `(syn::Item, SourceLocation)` (typically `source.items_all()`,
6+
//! with optional upstream filtering).
57
//! 2. [`core::Registry::write_rust`] resolves every required type via
68
//! a configured [`core::prebindgen_ext::PrebindgenExt`] and writes
79
//! the generated Rust bindings file. Language-agnostic — any

zenoh-jni/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn main() {
161161

162162
// ── Write Rust bindings ───────────────────────────────────────────
163163
let source = prebindgen::Source::new(zenoh_flat::PREBINDGEN_OUT_DIR);
164-
let mut registry = Registry::from_source(&source).expect("scan failed");
164+
let mut registry = Registry::from_items(source.items_all()).expect("scan failed");
165165
let rust_path = registry
166166
.write_rust(&jni, "zenoh_flat_jni.rs")
167167
.expect("write rust failed");

0 commit comments

Comments
 (0)