Jonas Platte 51d7875b2f Add 'ruma-api/' from commit '2151711f64e99a5da370d48fa92795f2d4799866'
git-subtree-dir: ruma-api
git-subtree-mainline: bb037a5c42c51567a3b9e41c2c131cef9867a4aa
git-subtree-split: 2151711f64e99a5da370d48fa92795f2d4799866
2020-06-05 01:56:19 +02:00

31 lines
875 B
Rust

//! Crate ruma-api-macros provides a procedural macro for easily generating
//! [ruma-api](https://github.com/ruma/ruma-api)-compatible endpoints.
//!
//! This crate should never be used directly; instead, use it through the
//! re-exports in ruma-api. Also note that for technical reasons, the
//! `ruma_api!` macro is only documented in ruma-api, not here.
#![allow(clippy::cognitive_complexity)]
#![recursion_limit = "256"]
extern crate proc_macro;
use std::convert::TryFrom as _;
use proc_macro::TokenStream;
use quote::ToTokens;
use syn::parse_macro_input;
use self::api::{Api, RawApi};
mod api;
#[proc_macro]
pub fn ruma_api(input: TokenStream) -> TokenStream {
let raw_api = parse_macro_input!(input as RawApi);
match Api::try_from(raw_api) {
Ok(api) => api.into_token_stream().into(),
Err(err) => err.to_compile_error().into(),
}
}