[−][src]Struct find_crate::Manifest
The manifest of cargo.
Note that this item must be used in the context of proc-macro.
Methods
impl<'a> Manifest<'a>[src]
pub fn new() -> Result<Self, Error>[src]
Constructs a new Manifest from the current Cargo.toml.
This function reads Cargo.toml in CARGO_MANIFEST_DIR as manifest.
pub fn from_path(manifest_path: &Path) -> Result<Self, Error>[src]
Constructs a new Manifest from the specified toml file.
pub fn dependencies(&self) -> &[&str][src]
Returns the kinds of dependencies to be searched. The default is
dependencies, dev-dependencies and build-dependencies.
pub fn set_dependencies(&mut self, dependencies: &'a [&'a str])[src]
Sets the kinds of dependencies to be searched. The default is
dependencies, dev-dependencies and build-dependencies.
pub fn rust_ident(&self) -> bool[src]
Returns whether or not to convert the name of the retrieved crate to a
valid rust identifier. The default is true.
pub fn set_rust_ident(&mut self, rust_ident: bool)[src]
Sets whether or not to convert the name of the retrieved crate to a valid rust identifier.
pub fn lock(&self) -> ManifestLock[src]
Lock the kinds of dependencies to be searched. This is more efficient when you want to search multiple times without changing the kinds of dependencies to be searched.
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; fn import() -> TokenStream { let manifest = Manifest::new().unwrap(); let name = manifest.find_name(|s| s == "foo" || s == "foo-core").unwrap(); 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;) }
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; fn import() -> TokenStream { let manifest = Manifest::new().unwrap(); let package = manifest.find(|s| s == "foo" || s == "foo-core").unwrap(); let name = Ident::new(package.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;) }
Trait Implementations
impl<'a> Clone for Manifest<'a>[src]
fn clone(&self) -> Manifest<'a>[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl<'a> Debug for Manifest<'a>[src]
Auto Trait Implementations
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,