2018-07-21 22:11:08 +00:00
|
|
|
#![feature(proc_macro_span, proc_macro_diagnostic)]
|
2018-08-15 09:07:17 +00:00
|
|
|
#![feature(crate_visibility_modifier)]
|
2018-07-21 22:11:08 +00:00
|
|
|
#![recursion_limit="256"]
|
|
|
|
|
2019-06-13 02:17:59 +00:00
|
|
|
#![warn(rust_2018_idioms)]
|
|
|
|
|
2018-07-21 22:11:08 +00:00
|
|
|
//! # Rocket Contrib - Code Generation
|
|
|
|
//! This crate implements the code generation portion of the Rocket Contrib
|
|
|
|
//! crate. This is for officially sanctioned contributor libraries that require
|
|
|
|
//! code generation of some kind.
|
|
|
|
//!
|
|
|
|
//! This crate includes custom derives and procedural macros and will expand
|
|
|
|
//! as-needed if future `rocket_contrib` features require code generation
|
|
|
|
//! facilities.
|
|
|
|
//!
|
|
|
|
//! ## Procedural Macros
|
|
|
|
//!
|
|
|
|
//! This crate implements the following procedural macros:
|
|
|
|
//!
|
|
|
|
//! * **databases**
|
|
|
|
//!
|
|
|
|
//! The syntax for the `databases` macro is:
|
|
|
|
//!
|
|
|
|
//! <pre>
|
|
|
|
//! macro := database(DATABASE_NAME)
|
|
|
|
//! DATABASE_NAME := (string literal)
|
|
|
|
//! </pre>
|
|
|
|
|
|
|
|
extern crate proc_macro;
|
2018-08-15 09:07:17 +00:00
|
|
|
|
|
|
|
#[allow(unused_imports)]
|
2018-07-21 22:11:08 +00:00
|
|
|
#[macro_use] extern crate quote;
|
|
|
|
|
2018-08-15 09:07:17 +00:00
|
|
|
#[allow(unused_imports)]
|
2018-10-29 04:09:04 +00:00
|
|
|
crate use devise::{syn, proc_macro2};
|
2018-07-21 22:11:08 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "database_attribute")]
|
|
|
|
mod database;
|
|
|
|
|
2018-08-15 09:07:17 +00:00
|
|
|
#[allow(unused_imports)]
|
2018-07-21 22:11:08 +00:00
|
|
|
use proc_macro::TokenStream;
|
|
|
|
|
2018-08-15 09:07:17 +00:00
|
|
|
/// The procedural macro for the `databases` annotation.
|
2018-07-21 22:11:08 +00:00
|
|
|
#[cfg(feature = "database_attribute")]
|
|
|
|
#[proc_macro_attribute]
|
|
|
|
pub fn database(attr: TokenStream, input: TokenStream) -> TokenStream {
|
2019-06-13 02:17:59 +00:00
|
|
|
crate::database::database_attr(attr, input).unwrap_or_else(|diag| {
|
2018-07-21 22:11:08 +00:00
|
|
|
diag.emit();
|
|
|
|
TokenStream::new()
|
|
|
|
})
|
|
|
|
}
|