Function find_crate::find_crate [−][src]
pub fn find_crate<P>(predicate: P) -> Result<Package, Error> where
P: FnMut(&str) -> bool,
Find the crate name from the current Cargo.toml
.
This function reads Cargo.toml
in CARGO_MANIFEST_DIR
as manifest.
Note that this function needs to be used in the context of proc-macro.
Examples
use find_crate::find_crate; use proc_macro2::{Ident, Span, TokenStream}; use quote::quote; fn import() -> TokenStream { let name = find_crate(|s| s == "foo" || s == "foo-core").unwrap().name; let name = Ident::new(&name, Span::call_site()); // If your proc-macro crate is 2018 edition, use `quote!(use #name as _foo;)` instead. quote!(extern crate #name as _foo;) }