Skip to main content

Name

Trait Name 

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

Source

fn as_name(&self) -> Cow<'_, str>

The name as a string, borrowed when the caller already holds one.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Name for Ident

Source§

fn as_name(&self) -> Cow<'_, str>

Source§

impl Name for String

Source§

fn as_name(&self) -> Cow<'_, str>

Source§

impl Name for str

Source§

fn as_name(&self) -> Cow<'_, str>

Source§

impl<T> Name for &T
where T: Name + ?Sized,

So a caller already holding a reference does not have to reborrow.

Source§

fn as_name(&self) -> Cow<'_, str>

Implementors§