fuels_rs/utils.rs
1use proc_macro2::{Ident, Span};
2use syn::Ident as SynIdent;
3
4/// Expands a identifier string into an token.
5pub fn ident(name: &str) -> Ident {
6 Ident::new(name, Span::call_site())
7}
8
9// Expands an identifier string into a token and appending `_` if the
10/// identifier is for a reserved keyword.
11///
12/// Parsing keywords like `self` can fail, in this case we add an underscore.
13pub fn safe_ident(name: &str) -> Ident {
14 syn::parse_str::<SynIdent>(name).unwrap_or_else(|_| ident(&format!("{}_", name)))
15}