pub trait Name: Sealed {
// Required method
fn as_name(&self) -> Cow<'_, str>;
}Expand description
A name a lookup can be performed with.
Exists because callers hold different spellings of the same fact: an adapter
walking captured items has a syn::Ident, a resolved reference has the
String inside a TypeId, and a test has a literal. One accessor takes all
three rather than each call site converting.
The conversion is moved, not removed. proc_macro2::Ident hashes by
to_string() and offers no borrow as str, so an Ident lookup allocates
wherever it happens; doing it here keeps &str and &String callers — among
them the per-edge and per-reference lookups in the scan and the resolver —
allocation-free.
Sealed: what may name an element is the language’s business, not a caller’s.
use prebindgen_flat::flat::Flat;
let flat = Flat::builder().source("source_ffi").build()?;
let ident = quote::format_ident!("test_function");
// The same element, whichever spelling the caller happens to hold.
assert!(flat.function("test_function").is_some());
assert!(flat.function(&ident).is_some());Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".