alchemy-macros 0.1.0

A crate containing macros used in Alchemy, the Rust cross-platform GUI framework.
Documentation
//! Utility functions, originally written by Bodil Stokke
//! over in [typed-html](https://github.com/bodil/typed-html).

use proc_macro2::{Ident, Span, TokenStream, TokenTree};

use std::str::FromStr;

pub fn new_raw(string: &str, span: Span) -> Ident {
    // Validate that it is an ident.
    let _ = Ident::new(string, span);

    let s = format!("r#{}", string);
    let tts = TokenStream::from_str(&s).unwrap();
    let mut ident = match tts.into_iter().next().unwrap() {
        TokenTree::Ident(ident) => ident,
        _ => unreachable!(),
    };
    ident.set_span(span);
    ident
}