[−][src]Struct find_crate::Manifest
The manifest of cargo.
Note that this function needs to be used in the context of proc-macro.
Fields
dependencies: Dependencies
The kind of dependencies to be searched.
Implementations
impl Manifest
[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_toml(manifest: Table) -> Self
[src]
Constructs a new Manifest
from a toml table.
pub fn find<P>(&self, predicate: P) -> Option<Package> where
P: FnMut(&str) -> bool,
[src]
P: FnMut(&str) -> bool,
Find the crate.
The argument of the closure is the original name of the package.
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(|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;) }
pub fn find2<P>(&self, predicate: P) -> Option<Package> where
P: FnMut(&str, &str) -> bool,
[src]
P: FnMut(&str, &str) -> bool,
Find the crate.
The first argument of the closure is the original name of the package and the second argument is the version of the package.
Examples
use find_crate::Manifest; use proc_macro2::{Ident, Span, TokenStream}; use quote::quote; use semver::{Version, VersionReq}; fn check_version(req: &str, version: &Version) -> bool { VersionReq::parse(req).unwrap().matches(version) } fn import() -> TokenStream { let version = Version::parse("0.3.0").unwrap(); let manifest = Manifest::new().unwrap(); let name = manifest .find2(|name, req| name == "foo" && check_version(req, &version)) .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;) }
pub fn crate_package(&self) -> Result<Package, Error>
[src]
The package for the crate that this manifest represents.
Examples
use find_crate::Manifest; use proc_macro2::{Ident, Span, TokenStream}; use quote::quote; fn current_crate_name() -> TokenStream { let manifest = Manifest::new().unwrap(); let current_crate_package = manifest.crate_package().unwrap(); let name = Ident::new(¤t_crate_package.name, Span::call_site()); quote!(#name) }
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Manifest
impl Send for Manifest
impl Sync for Manifest
impl Unpin for Manifest
impl UnwindSafe for Manifest
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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> 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>,