Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubelotix committed Nov 11, 2023
1 parent 28f0468 commit 4e2ab8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
16 changes: 8 additions & 8 deletions minecraft-entities-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ pub fn MinecraftEntity(attr: proc_macro::TokenStream, item: proc_macro::TokenStr
// Get struct name
let mut items = item.clone().into_iter();
match items.next() {
Some(TokenTree::Ident(ident)) if ident.to_string() == "pub" => (),
Some(TokenTree::Ident(ident)) if ident == "pub" => (),
Some(TokenTree::Punct(punct)) if punct.as_char() == '#' => {
items.next();
match items.next() {
Some(TokenTree::Ident(ident)) if ident.to_string() == "pub" => (),
Some(TokenTree::Ident(ident)) if ident == "pub" => (),
Some(other) => abort!(other.span(), "expected struct to be public"),
None => panic!("expected public struct, found nothing"),
}
Expand All @@ -54,7 +54,7 @@ pub fn MinecraftEntity(attr: proc_macro::TokenStream, item: proc_macro::TokenStr
None => panic!("expected public struct, found nothing"),
}
match items.next() {
Some(TokenTree::Ident(ident)) if ident.to_string() == "struct" => (),
Some(TokenTree::Ident(ident)) if ident == "struct" => (),
Some(other) => abort!(other.span(), "expected struct, found {:?}"),
None => panic!("expected struct, found nothing"),
}
Expand Down Expand Up @@ -124,7 +124,7 @@ pub fn MinecraftEntity(attr: proc_macro::TokenStream, item: proc_macro::TokenStr
abort!(params.span(), "expected parenthesis");
}
let mut params = params.stream().into_iter().peekable();
if matches!(params.peek(), Some(TokenTree::Ident(ident)) if ident.to_string() == "self") {
if matches!(params.peek(), Some(TokenTree::Ident(ident)) if ident == "self") {
params.next();
if matches!(params.peek(), Some(TokenTree::Punct(punct)) if punct.as_char() == ',') {
params.next();
Expand Down Expand Up @@ -264,7 +264,7 @@ pub fn MinecraftEntity(attr: proc_macro::TokenStream, item: proc_macro::TokenStr
replace_idents(element, &to_replace);
}
let mut inner_codes = TokenStream::new();
for (_, method, args) in defines.iter().filter(|(ty, _, _)| ty.to_string() == struct_name.to_string()) {
for (_, method, args) in defines.iter().filter(|(ty, _, _)| ty == &struct_name) {
let inner_code: TokenStream = match args.len() {
0 => String::from(r#"
fn method(self) -> Pin<Box<dyn Future<Output = ()>>> {{
Expand Down Expand Up @@ -318,7 +318,7 @@ pub fn MinecraftEntity(attr: proc_macro::TokenStream, item: proc_macro::TokenStr
replace_idents(element, &to_replace);
}
let mut inner_codes = TokenStream::new();
for (_, method, args) in defines.iter().filter(|(ty, _, _)| ty.to_string() == struct_name.to_string()) {
for (_, method, args) in defines.iter().filter(|(ty, _, _)| ty == &struct_name) {
let inner_code: TokenStream = match args.len() {
0 => String::from(r#"pub method: CallBack<Handler<This>>,"#),
1 => format!(r#"pub method: CallBack1<Handler<This>, {}>,"#, args[0].1),
Expand Down Expand Up @@ -356,7 +356,7 @@ pub fn MinecraftEntity(attr: proc_macro::TokenStream, item: proc_macro::TokenStr
replace_idents(element, &to_replace);
}
let mut inner_codes = TokenStream::new();
for (_, method, args) in defines.iter().filter(|(ty, _, _)| ty.to_string() == ascendant.to_string()) {
for (_, method, args) in defines.iter().filter(|(ty, _, _)| ty == ascendant) {
let inner_code: TokenStream = match args.len() {
0 => r#"method: |s| Box::pin(s.assume_other::<This>().method()),"#,
1 => r#"method: |s, arg1| Box::pin(s.assume_other::<This>().method(arg1)),"#,
Expand All @@ -380,7 +380,7 @@ pub fn MinecraftEntity(attr: proc_macro::TokenStream, item: proc_macro::TokenStr
let TokenTree::Group(ref mut group) = code.get_mut(i).unwrap() else {unreachable!()};
*group = Group::new(group.delimiter(), group.stream().into_iter().chain(inner_codes.into_iter()).collect());

if ascendant.to_string() != struct_name.to_string() {
if ascendant != &struct_name {
let inner_code: TokenStream = r#"..*ASCENDANT_METHODS_FOR_PARENT"#.parse().unwrap();
to_replace.insert("ASCENDANT_METHODS_FOR_PARENT", Ident::new(&format!("{}_METHODS_FOR_{}", ascendant.to_string().to_case(Case::ScreamingSnake), hierarchy[1].to_string().to_case(Case::ScreamingSnake)), ascendant.span()));
let mut inner_code = inner_code.clone().into_iter().collect::<Vec<_>>();
Expand Down
10 changes: 8 additions & 2 deletions minecraft-entities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,20 @@ pub(crate) use minecraft_protocol::{
nbt::NbtTag,
packets::UUID
};
use std::{pin::Pin, future::Future};

pub type Eid = u32;


use std::{pin::Pin, future::Future, sync::{Mutex, Arc}};
#[allow(dead_code)]
type CallBack<O> = fn(O) -> Pin<Box<dyn Future<Output = ()>>>;
#[allow(dead_code)]
type CallBack1<O, I> = fn(O, I) -> Pin<Box<dyn Future<Output = ()>>>;
#[allow(dead_code)]
type CallBack2<O, I, J> = fn(O, I, J) -> Pin<Box<dyn Future<Output = ()>>>;
#[allow(dead_code)]
type CallBack3<O, I, J> = fn(O, I, J) -> Pin<Box<dyn Future<Output = ()>>>;
#[allow(dead_code)]
type CallBack4<O, I, J> = fn(O, I, J) -> Pin<Box<dyn Future<Output = ()>>>;

pub trait TryAsEntityRef<T> {
fn try_as_entity_ref(&self) -> Option<&T>;
Expand Down

0 comments on commit 4e2ab8b

Please sign in to comment.