Use format_ident! in import helper functions
This commit is contained in:
parent
3cd6dd3dfd
commit
105bb9cf67
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::TokenStream;
|
||||||
use proc_macro_crate::{crate_name, FoundCrate};
|
use proc_macro_crate::{crate_name, FoundCrate};
|
||||||
use quote::quote;
|
use quote::{format_ident, quote};
|
||||||
use syn::{AttrStyle, Attribute, Ident, Lifetime};
|
use syn::{AttrStyle, Attribute, Lifetime};
|
||||||
|
|
||||||
/// Generates a `TokenStream` of lifetime identifiers `<'lifetime>`.
|
/// Generates a `TokenStream` of lifetime identifiers `<'lifetime>`.
|
||||||
pub(crate) fn unique_lifetimes_to_tokens<'a, I: IntoIterator<Item = &'a Lifetime>>(
|
pub(crate) fn unique_lifetimes_to_tokens<'a, I: IntoIterator<Item = &'a Lifetime>>(
|
||||||
@ -25,11 +25,11 @@ pub(crate) fn is_valid_endpoint_path(string: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn import_ruma_api() -> TokenStream {
|
pub(crate) fn import_ruma_api() -> TokenStream {
|
||||||
if let Ok(FoundCrate::Name(possibly_renamed)) = crate_name("ruma-api") {
|
if let Ok(FoundCrate::Name(name)) = crate_name("ruma-api") {
|
||||||
let import = Ident::new(&possibly_renamed, Span::call_site());
|
let import = format_ident!("{}", name);
|
||||||
quote! { ::#import }
|
quote! { ::#import }
|
||||||
} else if let Ok(FoundCrate::Name(possibly_renamed)) = crate_name("ruma") {
|
} else if let Ok(FoundCrate::Name(name)) = crate_name("ruma") {
|
||||||
let import = Ident::new(&possibly_renamed, Span::call_site());
|
let import = format_ident!("{}", name);
|
||||||
quote! { ::#import::api }
|
quote! { ::#import::api }
|
||||||
} else {
|
} else {
|
||||||
quote! { ::ruma_api }
|
quote! { ::ruma_api }
|
||||||
|
@ -12,8 +12,8 @@ use event_parse::EventEnumInput;
|
|||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use proc_macro2 as pm2;
|
use proc_macro2 as pm2;
|
||||||
use proc_macro_crate::{crate_name, FoundCrate};
|
use proc_macro_crate::{crate_name, FoundCrate};
|
||||||
use quote::quote;
|
use quote::{format_ident, quote};
|
||||||
use syn::{parse_macro_input, DeriveInput, Ident};
|
use syn::{parse_macro_input, DeriveInput};
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
event::expand_event, event_content::expand_event_content, event_enum::expand_event_enum,
|
event::expand_event, event_content::expand_event_content, event_enum::expand_event_enum,
|
||||||
@ -91,11 +91,11 @@ pub fn derive_state_event(input: TokenStream) -> TokenStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn import_ruma_events() -> pm2::TokenStream {
|
pub(crate) fn import_ruma_events() -> pm2::TokenStream {
|
||||||
if let Ok(FoundCrate::Name(possibly_renamed)) = crate_name("ruma-events") {
|
if let Ok(FoundCrate::Name(name)) = crate_name("ruma-events") {
|
||||||
let import = Ident::new(&possibly_renamed, pm2::Span::call_site());
|
let import = format_ident!("{}", name);
|
||||||
quote! { ::#import }
|
quote! { ::#import }
|
||||||
} else if let Ok(FoundCrate::Name(possibly_renamed)) = crate_name("ruma") {
|
} else if let Ok(FoundCrate::Name(name)) = crate_name("ruma") {
|
||||||
let import = Ident::new(&possibly_renamed, pm2::Span::call_site());
|
let import = format_ident!("{}", name);
|
||||||
quote! { ::#import::events }
|
quote! { ::#import::events }
|
||||||
} else {
|
} else {
|
||||||
quote! { ::ruma_events }
|
quote! { ::ruma_events }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use proc_macro2::{Ident, Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
use proc_macro_crate::{crate_name, FoundCrate};
|
use proc_macro_crate::{crate_name, FoundCrate};
|
||||||
use quote::quote;
|
use quote::{format_ident, quote};
|
||||||
use syn::{ItemEnum, LitStr, Variant};
|
use syn::{ItemEnum, LitStr, Variant};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -9,11 +9,11 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn import_ruma_serde() -> TokenStream {
|
pub fn import_ruma_serde() -> TokenStream {
|
||||||
if let Ok(FoundCrate::Name(possibly_renamed)) = crate_name("ruma-serde") {
|
if let Ok(FoundCrate::Name(name)) = crate_name("ruma-serde") {
|
||||||
let import = Ident::new(&possibly_renamed, Span::call_site());
|
let import = format_ident!("{}", name);
|
||||||
quote! { ::#import }
|
quote! { ::#import }
|
||||||
} else if let Ok(FoundCrate::Name(possibly_renamed)) = crate_name("ruma") {
|
} else if let Ok(FoundCrate::Name(name)) = crate_name("ruma") {
|
||||||
let import = Ident::new(&possibly_renamed, Span::call_site());
|
let import = format_ident!("{}", name);
|
||||||
quote! { ::#import::serde }
|
quote! { ::#import::serde }
|
||||||
} else {
|
} else {
|
||||||
quote! { ::ruma_serde }
|
quote! { ::ruma_serde }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user