dioxus_rsx/
util.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#![allow(unused)]

use proc_macro2::TokenStream as TokenStream2;
use std::{fmt::Debug, hash::Hash};
use syn::{
    ext::IdentExt,
    parse::{Parse, ParseBuffer},
    Ident,
};

/// Parse a raw ident and return a new ident with the r# prefix added
pub fn parse_raw_ident(parse_buffer: &ParseBuffer) -> syn::Result<Ident> {
    // First try to parse as a normal ident
    if let Ok(ident) = Ident::parse(parse_buffer) {
        return Ok(ident);
    }
    // If that fails, try to parse as a raw ident
    let ident = Ident::parse_any(parse_buffer)?;
    Ok(Ident::new_raw(&ident.to_string(), ident.span()))
}