[−][src]Struct find_crate::ManifestLock
A locked reference to the dependencies tables of Manifest to be searched.
Methods
impl<'a> ManifestLock<'a>[src]
pub fn find_name<P>(&self, predicate: P) -> Option<Cow<str>> where
P: FnMut(&str) -> bool, [src]
P: FnMut(&str) -> bool,
Find the crate name.
Examples
use find_crate::Manifest; use proc_macro2::{Ident, Span, TokenStream}; use quote::quote; const CRATE_NAMES: &[&[&str]] = &[ &["foo", "foo-core"], &["bar", "bar-util", "bar-core"], &["baz"], ]; fn imports() -> TokenStream { let mut tts = TokenStream::new(); let manifest = Manifest::new().unwrap(); let manifest = manifest.lock(); for names in CRATE_NAMES { let name = manifest.find_name(|s| names.iter().any(|x| s == *x)).unwrap(); let name = Ident::new(&name, Span::call_site()); let import_name = Ident::new(&format!("_{}", names[0]), Span::call_site()); // If your proc-macro crate is 2018 edition, use `quote!(use #name as #import_name;)` instead. tts.extend(quote!(extern crate #name as #import_name;)); } tts }
pub fn find<P>(&self, predicate: P) -> Option<Package> where
P: FnMut(&str) -> bool, [src]
P: FnMut(&str) -> bool,
Find the crate.
Examples
use find_crate::Manifest; use proc_macro2::{Ident, Span, TokenStream}; use quote::quote; const CRATE_NAMES: &[&[&str]] = &[ &["foo", "foo-core"], &["bar", "bar-util", "bar-core"], &["baz"], ]; fn imports() -> TokenStream { let mut tts = TokenStream::new(); let manifest = Manifest::new().unwrap(); let manifest = manifest.lock(); for names in CRATE_NAMES { let package = manifest.find(|s| names.iter().any(|x| s == *x)).unwrap(); let name = Ident::new(package.name(), Span::call_site()); let import_name = Ident::new(&format!("_{}", names[0]), Span::call_site()); // If your proc-macro crate is 2018 edition, use `quote!(use #name as #import_name;)` instead. tts.extend(quote!(extern crate #name as #import_name;)); } tts }
Trait Implementations
impl<'a> Clone for ManifestLock<'a>[src]
fn clone(&self) -> ManifestLock<'a>[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl<'a> Debug for ManifestLock<'a>[src]
Auto Trait Implementations
impl<'a> Send for ManifestLock<'a>
impl<'a> Sync for ManifestLock<'a>
Blanket Implementations
impl<T> From<T> for T[src]
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,