docstring-attr-silly 0.1.0

A very silly #[docstring] macro for your code
Documentation
//! # `#[docstring]`
//!
//! This crate allows you to annotate your crates with `#[docstring]`, and
//! subsequently use Python-style "docstrings" in them:
//!
//! ```rust
//! # use docstring_attr_silly::docstring;
//!
//! #[docstring]
//! fn foobar() -> i32 {
//!     "returns a really cool number";
//!
//!     4
//! }
//! ```
//!
//! ## Features
//!
//! Sure!
//!
//! ## Known Limitations
//!
//! 1. It's really silly.
//! 2. Needs `;` after the docstring because I was too lazy
//!    to make it work without (see source code)

#[proc_macro_attribute]
pub fn docstring(_: TokenStream, item: TokenStream) -> TokenStream {
    let mut fn_ = parse_macro_input!(item as ItemFn);

    if let Some(
        Stmt::Expr(
            Expr::Lit(
                ExprLit { lit: Lit::Str(s), .. }
            ),
            _
        )
    ) = fn_.block.stmts.get(0) {

        let s = s.clone();
        fn_.block.stmts.remove(0);
        fn_.attrs.push(parse_quote! { #![doc = #s] });
    }

    fn_.into_token_stream().into()
}

use proc_macro::TokenStream;
use quote::ToTokens;
use syn::*;