Skip to content

Commit

Permalink
update to rust edition 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Feb 22, 2025
1 parent bdd2fc9 commit 34f53ba
Show file tree
Hide file tree
Showing 109 changed files with 569 additions and 496 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ resolver = "2"

[workspace.package]
version = "0.11.0+mc1.21.4"
edition = "2021"
edition = "2024"
license = "MIT"
repository = "https://github.com/azalea-rs/azalea"
# homepage = "https://github.com/azalea-rs/azalea"
Expand Down
6 changes: 3 additions & 3 deletions azalea-auth/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pub async fn get_ms_auth_token(
tokio::time::sleep(std::time::Duration::from_secs(res.interval)).await;

trace!("Polling to check if user has logged in...");
if let Ok(access_token_response) = client
let res = client
.post(format!(
"https://login.live.com/oauth20_token.srf?client_id={client_id}"
))
Expand All @@ -372,8 +372,8 @@ pub async fn get_ms_auth_token(
.send()
.await?
.json::<AccessTokenResponse>()
.await
{
.await;
if let Ok(access_token_response) = res {
trace!("access_token_response: {:?}", access_token_response);
let expires_at = SystemTime::now()
+ std::time::Duration::from_secs(access_token_response.expires_in);
Expand Down
2 changes: 1 addition & 1 deletion azalea-auth/src/certs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use base64::Engine;
use chrono::{DateTime, Utc};
use rsa::{pkcs8::DecodePrivateKey, RsaPrivateKey};
use rsa::{RsaPrivateKey, pkcs8::DecodePrivateKey};
use serde::Deserialize;
use thiserror::Error;
use tracing::trace;
Expand Down
2 changes: 1 addition & 1 deletion azalea-auth/src/sessionserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub async fn serverside_auth(
StatusCode::FORBIDDEN => {
return Err(ServerSessionServerError::Unknown(
res.json::<ForbiddenError>().await?.error,
))
));
}
status_code => {
// log the headers
Expand Down
29 changes: 15 additions & 14 deletions azalea-block/azalea-block-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use proc_macro::TokenStream;
use proc_macro2::TokenTree;
use quote::quote;
use syn::{
braced,
Expr, Ident, LitStr, Token, braced,
ext::IdentExt,
parenthesized,
parse::{Parse, ParseStream, Result},
parse_macro_input,
punctuated::Punctuated,
token, Expr, Ident, LitStr, Token,
token,
};
use utils::{combinations_of, to_pascal_case};

Expand Down Expand Up @@ -511,13 +511,13 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
Ident::new(&combination[i].to_string(), proc_macro2::Span::call_site());

// this terrible code just gets the property default as a string
let property_default_as_string = if let TokenTree::Ident(ident) =
property.default.clone().into_iter().last().unwrap()
{
ident.to_string()
} else {
panic!()
};
let property_default_as_string =
match property.default.clone().into_iter().last().unwrap() {
TokenTree::Ident(ident) => ident.to_string(),
_ => {
panic!()
}
};
if property_default_as_string != combination[i] {
is_default = false;
}
Expand Down Expand Up @@ -565,15 +565,16 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
let Some(default_state_id) = default_state_id else {
let defaults = properties_with_name
.iter()
.map(|p| {
if let TokenTree::Ident(i) = p.default.clone().into_iter().last().unwrap() {
i.to_string()
} else {
.map(|p| match p.default.clone().into_iter().last().unwrap() {
TokenTree::Ident(i) => i.to_string(),
_ => {
panic!()
}
})
.collect::<Vec<_>>();
panic!("Couldn't get default state id for {block_name_pascal_case}, combinations={block_properties_vec:?}, defaults={defaults:?}")
panic!(
"Couldn't get default state id for {block_name_pascal_case}, combinations={block_properties_vec:?}, defaults={defaults:?}"
)
};

// 7035..=7058 => {
Expand Down
4 changes: 2 additions & 2 deletions azalea-block/src/range.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{
collections::{hash_set, HashSet},
collections::{HashSet, hash_set},
ops::{Add, RangeInclusive},
};

use crate::{block_state::BlockStateIntegerRepr, BlockState};
use crate::{BlockState, block_state::BlockStateIntegerRepr};

#[derive(Debug, Clone)]
pub struct BlockStates {
Expand Down
149 changes: 86 additions & 63 deletions azalea-brigadier/src/command_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,30 @@ impl<S> CommandDispatcher<S> {
1
}) {
reader.skip();
if let Some(redirect) = &child.read().redirect {
let child_context =
CommandContextBuilder::new(self, source, redirect.clone(), reader.cursor);
let parse = self
.parse_nodes(redirect, &reader, child_context)
.expect("Parsing nodes failed");
context.with_child(Rc::new(parse.context));
return Ok(ParseResults {
context,
reader: parse.reader,
exceptions: parse.exceptions,
});
} else {
let parse = self
.parse_nodes(&child, &reader, context)
.expect("Parsing nodes failed");
potentials.push(parse);
match &child.read().redirect {
Some(redirect) => {
let child_context = CommandContextBuilder::new(
self,
source,
redirect.clone(),
reader.cursor,
);
let parse = self
.parse_nodes(redirect, &reader, child_context)
.expect("Parsing nodes failed");
context.with_child(Rc::new(parse.context));
return Ok(ParseResults {
context,
reader: parse.reader,
exceptions: parse.exceptions,
});
}
_ => {
let parse = self
.parse_nodes(&child, &reader, context)
.expect("Parsing nodes failed");
potentials.push(parse);
}
}
} else {
potentials.push(ParseResults {
Expand Down Expand Up @@ -215,11 +222,14 @@ impl<S> CommandDispatcher<S> {
pub fn find_node(&self, path: &[&str]) -> Option<Arc<RwLock<CommandNode<S>>>> {
let mut node = self.root.clone();
for name in path {
if let Some(child) = node.clone().read().child(name) {
node = child;
} else {
return None;
}
match node.clone().read().child(name) {
Some(child) => {
node = child;
}
_ => {
return None;
}
};
}
Some(node)
}
Expand Down Expand Up @@ -258,31 +268,41 @@ impl<S> CommandDispatcher<S> {
let modifier = &context.modifier;
if let Some(modifier) = modifier {
let results = modifier(context);
if let Ok(results) = results {
if !results.is_empty() {
next.extend(results.iter().map(|s| child.copy_for(s.clone())));
match results {
Ok(results) => {
if !results.is_empty() {
next.extend(
results.iter().map(|s| child.copy_for(s.clone())),
);
}
}
} else {
// TODO
// self.consumer.on_command_complete(context, false, 0);
if !forked {
return Err(results.err().unwrap());
_ => {
// TODO
// self.consumer.on_command_complete(context, false, 0);
if !forked {
return Err(results.err().unwrap());
}
}
}
} else {
next.push(child.copy_for(context.source.clone()));
}
}
} else if let Some(context_command) = &context.command {
found_command = true;
} else {
match &context.command {
Some(context_command) => {
found_command = true;

let value = context_command(context);
result += value;
// consumer.on_command_complete(context, true, value);
successful_forks += 1;
let value = context_command(context);
result += value;
// consumer.on_command_complete(context, true, value);
successful_forks += 1;

// TODO: allow context_command to error and handle those
// errors
// TODO: allow context_command to error and handle
// those errors
}
_ => {}
}

Check warning on line 305 in azalea-brigadier/src/command_dispatcher.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> azalea-brigadier/src/command_dispatcher.rs:292:21 | 292 | / match &context.command { 293 | | Some(context_command) => { 294 | | found_command = true; ... | 304 | | _ => {} 305 | | } | |_____________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match = note: `#[warn(clippy::single_match)]` on by default help: try | 292 ~ if let Some(context_command) = &context.command { 293 + found_command = true; 294 + 295 + let value = context_command(context); 296 + result += value; 297 + // consumer.on_command_complete(context, true, value); 298 + successful_forks += 1; 299 + 300 + // TODO: allow context_command to error and handle 301 + // those errors 302 + } |
}
}

Expand Down Expand Up @@ -332,32 +352,35 @@ impl<S> CommandDispatcher<S> {
if node.command.is_some() {
result.push(prefix.to_owned());
}
if let Some(redirect) = &node.redirect {
let redirect = if redirect.data_ptr() == self.root.data_ptr() {
"...".to_string()
} else {
format!("-> {}", redirect.read().usage_text())
};
if prefix.is_empty() {
result.push(format!("{} {redirect}", node.usage_text()));
} else {
result.push(format!("{prefix} {redirect}"));
match &node.redirect {
Some(redirect) => {
let redirect = if redirect.data_ptr() == self.root.data_ptr() {
"...".to_string()
} else {
format!("-> {}", redirect.read().usage_text())
};
if prefix.is_empty() {
result.push(format!("{} {redirect}", node.usage_text()));
} else {
result.push(format!("{prefix} {redirect}"));
}
}
} else {
for child in node.children.values() {
let child = child.read();
self.get_all_usage_recursive(
&child,
source,
result,
if prefix.is_empty() {
child.usage_text()
} else {
format!("{prefix} {}", child.usage_text())
}
.as_str(),
restricted,
);
_ => {
for child in node.children.values() {
let child = child.read();
self.get_all_usage_recursive(
&child,
source,
result,
if prefix.is_empty() {
child.usage_text()
} else {
format!("{prefix} {}", child.usage_text())
}
.as_str(),
restricted,
);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion azalea-brigadier/src/context/command_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{any::Any, collections::HashMap, fmt::Debug, rc::Rc, sync::Arc};

use parking_lot::RwLock;

use super::{parsed_command_node::ParsedCommandNode, string_range::StringRange, ParsedArgument};
use super::{ParsedArgument, parsed_command_node::ParsedCommandNode, string_range::StringRange};
use crate::{
modifier::RedirectModifier,
tree::{Command, CommandNode},
Expand Down
28 changes: 14 additions & 14 deletions azalea-brigadier/src/context/command_context_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{collections::HashMap, fmt::Debug, rc::Rc, sync::Arc};
use parking_lot::RwLock;

use super::{
command_context::CommandContext, parsed_command_node::ParsedCommandNode,
string_range::StringRange, suggestion_context::SuggestionContext, ParsedArgument,
ParsedArgument, command_context::CommandContext, parsed_command_node::ParsedCommandNode,
string_range::StringRange, suggestion_context::SuggestionContext,
};
use crate::{
command_dispatcher::CommandDispatcher,
Expand Down Expand Up @@ -107,18 +107,18 @@ impl<'a, S> CommandContextBuilder<'a, S> {
}

if self.range.end() < cursor {
if let Some(child) = &self.child {
child.find_suggestion_context(cursor)
} else if let Some(last) = self.nodes.last() {
SuggestionContext {
parent: Arc::clone(&last.node),
start_pos: last.range.end() + 1,
}
} else {
SuggestionContext {
parent: Arc::clone(&self.root),
start_pos: self.range.start(),
}
match &self.child {
Some(child) => child.find_suggestion_context(cursor),
_ => match self.nodes.last() {
Some(last) => SuggestionContext {
parent: Arc::clone(&last.node),
start_pos: last.range.end() + 1,
},
_ => SuggestionContext {
parent: Arc::clone(&self.root),
start_pos: self.range.start(),
},
},
}
} else {
let mut prev = &self.root;
Expand Down
27 changes: 18 additions & 9 deletions azalea-brigadier/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,27 @@ impl<S> PartialEq for CommandNode<S> {
}
}

if let Some(selfexecutes) = &self.command {
// idk how to do this better since we can't compare `dyn Fn`s
if let Some(otherexecutes) = &other.command {
#[allow(ambiguous_wide_pointer_comparisons)]
if !Arc::ptr_eq(selfexecutes, otherexecutes) {
match &self.command {
Some(selfexecutes) => {
// idk how to do this better since we can't compare `dyn Fn`s
match &other.command {
Some(otherexecutes) =>
{
#[allow(ambiguous_wide_pointer_comparisons)]
if !Arc::ptr_eq(selfexecutes, otherexecutes) {
return false;
}
}
_ => {
return false;
}
}
}
_ => {
if other.command.is_some() {
return false;
}
} else {
return false;
}
} else if other.command.is_some() {
return false;
}
true
}
Expand Down
Loading

0 comments on commit 34f53ba

Please sign in to comment.