find-crate
Find the crate name from the current Cargo.toml
.
When writing declarative macros, $crate
representing the current crate is
very useful, but procedural macros do not have this. If you know the current
name of the crate you want to use, you can do the same thing as $crate
.
This crate provides the features to make it easy.
Note: This crate is intended to provide more powerful features such as support for multiple crate names and versions. For general purposes, proc-macro-crate, which provides a simpler API, may be easier to use.
Usage
Add this to your Cargo.toml
:
[]
= "0.5"
The current find-crate requires Rust 1.31 or later.
Examples
find_crate()
gets the crate name from the current Cargo.toml
.
use find_crate;
use ;
use quote;
As in this example, it is easy to handle cases where proc-macro is exported from multiple crates.
use find_crate;
use ;
use quote;
Using Manifest
to search for multiple crates. It is much more efficient than using find_crate()
for each crate.
use Manifest;
use ;
use ;
const CRATE_NAMES: & = &;
By default it will be searched from dependencies
and dev-dependencies
.
Also, find_crate()
and Manifest::new()
read Cargo.toml
in CARGO_MANIFEST_DIR
as manifest.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.