Skip to content

Commit

Permalink
remove external_type_uuid macro (#4018)
Browse files Browse the repository at this point in the history
# Objective

- Macro `external_type_uuid` seems unused
- https://docs.rs/bevy/latest/bevy/reflect/macro.external_type_uuid.html

## Solution

- Remove it and see if it was? There is a derive for the same trait that is used everywhere (`#[derive(TypeUuid)]`) and is a better api
  • Loading branch information
mockersf committed Feb 22, 2022
1 parent e4203c3 commit b3a2cbb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
5 changes: 0 additions & 5 deletions crates/bevy_reflect/bevy_reflect_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,6 @@ pub fn type_uuid_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStre
type_uuid::type_uuid_derive(input)
}

#[proc_macro]
pub fn external_type_uuid(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
type_uuid::external_type_uuid(tokens)
}

#[proc_macro_attribute]
pub fn reflect_trait(args: TokenStream, input: TokenStream) -> TokenStream {
reflect_trait::reflect_trait(&args, input)
Expand Down
37 changes: 1 addition & 36 deletions crates/bevy_reflect/bevy_reflect_derive/src/type_uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate proc_macro;

use bevy_macro_utils::BevyManifest;
use quote::{quote, ToTokens};
use syn::{parse::*, *};
use syn::*;
use uuid::Uuid;

pub fn type_uuid_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
Expand Down Expand Up @@ -65,38 +65,3 @@ pub fn type_uuid_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStre
};
gen.into()
}

struct ExternalDeriveInput {
path: ExprPath,
uuid_str: LitStr,
}

impl Parse for ExternalDeriveInput {
fn parse(input: ParseStream) -> Result<Self> {
let path = input.parse()?;
input.parse::<Token![,]>()?;
let uuid_str = input.parse()?;
Ok(Self { path, uuid_str })
}
}

pub fn external_type_uuid(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
let ExternalDeriveInput { path, uuid_str } = parse_macro_input!(tokens as ExternalDeriveInput);

let uuid = Uuid::parse_str(&uuid_str.value()).expect("Value was not a valid UUID.");

let bytes = uuid
.as_bytes()
.iter()
.map(|byte| format!("{:#X}", byte))
.map(|byte_str| syn::parse_str::<LitInt>(&byte_str).unwrap());

let gen = quote! {
impl crate::TypeUuid for #path {
const TYPE_UUID: Uuid = uuid::Uuid::from_bytes([
#( #bytes ),*
]);
}
};
gen.into()
}

0 comments on commit b3a2cbb

Please sign in to comment.