Use Rust 1.62.0 features

This commit is contained in:
Ryan 2022-06-30 13:22:08 -07:00
parent 560163fd2e
commit 6ef634ca2c
5 changed files with 25 additions and 84 deletions

View file

@ -18,7 +18,6 @@ base64 = "0.13"
bitfield-struct = "0.1"
bitvec = "1"
byteorder = "1"
bytes = "1"
cfb8 = "0.7"
flate2 = "1"
flume = "0.10"
@ -26,8 +25,6 @@ futures = "0.3"
hematite-nbt = "0.5"
log = "0.4"
num = "0.4"
ordered-float = "3.0.0"
parking_lot = "0.12"
paste = "1"
rand = "0.8"
rayon = "1"

View file

@ -61,19 +61,14 @@ impl Default for Biome {
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
pub enum BiomePrecipitation {
#[default]
Rain,
Snow,
None,
}
impl Default for BiomePrecipitation {
fn default() -> Self {
Self::Rain
}
}
/// Minecraft handles grass colors for swamps and dark oak forests in a special
/// way.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]

View file

@ -79,10 +79,11 @@ impl Encode for VillagerData {
}
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
pub enum VillagerType {
Desert,
Jungle,
#[default]
Plains,
Savanna,
Snow,
@ -90,14 +91,9 @@ pub enum VillagerType {
Taiga,
}
impl Default for VillagerType {
fn default() -> Self {
Self::Plains
}
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
pub enum VillagerProfession {
#[default]
None,
Armorer,
Butcher,
@ -115,14 +111,9 @@ pub enum VillagerProfession {
Weaponsmith,
}
impl Default for VillagerProfession {
fn default() -> Self {
Self::None
}
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
pub enum Pose {
#[default]
Standing,
FallFlying,
Sleeping,
@ -139,12 +130,6 @@ pub enum Pose {
Digging,
}
impl Default for Pose {
fn default() -> Self {
Self::Standing
}
}
impl Encode for Pose {
fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> {
VarInt(*self as i32).encode(w)
@ -152,26 +137,22 @@ impl Encode for Pose {
}
/// The main hand of a player.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
pub enum MainHand {
Left,
#[default]
Right,
}
impl Default for MainHand {
fn default() -> Self {
Self::Right
}
}
impl Encode for MainHand {
fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> {
(*self as u8).encode(w)
}
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
pub enum BoatVariant {
#[default]
Oak,
Spruce,
Birch,
@ -180,21 +161,16 @@ pub enum BoatVariant {
DarkOak,
}
impl Default for BoatVariant {
fn default() -> Self {
Self::Oak
}
}
impl Encode for BoatVariant {
fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> {
VarInt(*self as i32).encode(w)
}
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
pub enum CatVariant {
Tabby,
#[default]
Black,
Red,
Siamese,
@ -207,48 +183,32 @@ pub enum CatVariant {
AllBlack,
}
impl Default for CatVariant {
fn default() -> Self {
CatVariant::Black
}
}
impl Encode for CatVariant {
fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> {
VarInt(*self as i32).encode(w)
}
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
pub enum FrogVariant {
#[default]
Temperate,
Warm,
Cold,
}
impl Default for FrogVariant {
fn default() -> Self {
FrogVariant::Temperate
}
}
impl Encode for FrogVariant {
fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> {
VarInt(*self as i32).encode(w)
}
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
pub enum PaintingVariant {
#[default]
Default, // TODO
}
impl Default for PaintingVariant {
fn default() -> Self {
PaintingVariant::Default
}
}
impl Encode for PaintingVariant {
fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> {
VarInt(*self as i32).encode(w)

View file

@ -944,8 +944,9 @@ pub mod play {
}
def_enum! {
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
GameMode: u8 {
#[default]
Survival = 0,
Creative = 1,
Adventure = 2,
@ -953,12 +954,6 @@ pub mod play {
}
}
impl Default for GameMode {
fn default() -> Self {
GameMode::Survival
}
}
def_struct! {
EntityPosition 0x26 {
entity_id: VarInt,
@ -996,8 +991,9 @@ pub mod play {
}
def_enum! {
#[derive(Copy, PartialEq, Eq)]
#[derive(Copy, PartialEq, Eq, Default)]
ChatMessageType: VarInt {
#[default]
Chat = 0,
SystemMessage = 1,
GameInfo = 2,
@ -1009,12 +1005,6 @@ pub mod play {
}
}
impl Default for ChatMessageType {
fn default() -> Self {
ChatMessageType::Chat
}
}
def_enum! {
PlayerInfo 0x34: VarInt {
AddPlayer: Vec<PlayerInfoAddPlayer> = 0,

View file

@ -3,14 +3,13 @@ use std::error::Error;
use std::iter::FusedIterator;
use std::net::SocketAddr;
use std::sync::atomic::{AtomicI64, Ordering};
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::{Duration, Instant};
use anyhow::{bail, ensure, Context};
use flume::{Receiver, Sender};
use num::BigInt;
use parking_lot::Mutex;
use rand::rngs::OsRng;
use rayon::iter::ParallelIterator;
use reqwest::Client as HttpClient;
@ -199,7 +198,7 @@ impl Server {
E: Into<Box<dyn Error + Send + Sync + 'static>>,
{
self.0.connection_sema.close();
*self.0.shutdown_result.lock() = Some(res.into().map_err(|e| e.into()));
*self.0.shutdown_result.lock().unwrap() = Some(res.into().map_err(|e| e.into()));
}
}
@ -351,7 +350,7 @@ fn do_update_loop(server: Server, worlds: &mut Worlds) -> ShutdownResult {
let mut tick_start = Instant::now();
loop {
if let Some(res) = server.0.shutdown_result.lock().take() {
if let Some(res) = server.0.shutdown_result.lock().unwrap().take() {
return res;
}