[][src]Struct find_crate::Manifest

pub struct Manifest<'a> { /* fields omitted */ }

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]

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]

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_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

impl<'a> Send for Manifest<'a>

impl<'a> Sync for Manifest<'a>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]