From 3f3737853f5653a54523abec60a7e954fc851e48 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 10 Jun 2024 03:03:28 -0700 Subject: refactor: bump nightly rust and fix lints --- rust-toolchain.toml | 2 +- src/main.rs | 4 +-- src/ppm.rs | 98 ++++++++++++++++++++++++++++------------------------- 3 files changed, 55 insertions(+), 49 deletions(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 099ab4b..1aa9c83 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2022-03-08" +channel = "nightly-2023-06-10" diff --git a/src/main.rs b/src/main.rs index b12f6c5..9a77a70 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ // Copyright (C) 2022-2022 Fuwn // SPDX-License-Identifier: MIT -#![feature(decl_macro, generators, generator_trait, once_cell)] +#![feature(decl_macro, generators, generator_trait, lazy_cell)] #![deny( warnings, nonstandard_style, @@ -125,5 +125,5 @@ fn main() { } } - println!("converted {}({}) to {}", path, index, out_path); + println!("converted {path}({index}) to {out_path}"); } diff --git a/src/ppm.rs b/src/ppm.rs index b579422..e0377a8 100644 --- a/src/ppm.rs +++ b/src/ppm.rs @@ -7,28 +7,32 @@ use std::{ collections::HashMap, fs, io::{Cursor, Read}, - lazy::SyncLazy, ops::Generator, + sync::OnceLock, }; use byteorder::{LittleEndian, ReadBytesExt}; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{DateTime, NaiveDateTime, TimeZone, Utc}; /// Flipnote speed -> frames per second -static FRAMERATES: SyncLazy> = SyncLazy::new(|| { - let mut hashmap = HashMap::new(); - - hashmap.insert(1, 0.5); - hashmap.insert(2, 1.0); - hashmap.insert(3, 2.0); - hashmap.insert(4, 4.0); - hashmap.insert(5, 6.0); - hashmap.insert(6, 12.0); - hashmap.insert(7, 20.0); - hashmap.insert(8, 30.0); - - hashmap -}); +fn framerates() -> &'static HashMap { + static FRAMERATES: OnceLock> = OnceLock::new(); + + FRAMERATES.get_or_init(|| { + let mut hashmap = HashMap::new(); + + hashmap.insert(1, 0.5); + hashmap.insert(2, 1.0); + hashmap.insert(3, 2.0); + hashmap.insert(4, 4.0); + hashmap.insert(5, 6.0); + hashmap.insert(6, 12.0); + hashmap.insert(7, 20.0); + hashmap.insert(8, 30.0); + + hashmap + }) +} /// Thumbnail bitmap RGB colours // const THUMBNAIL_PALETTE: &'static [(u64, u64, u64)] = &[ @@ -209,11 +213,12 @@ impl PPMParser { // Timestamp is stored as the number of seconds since 2000, January, 1st let timestamp = self.stream.read_u32::().unwrap(); - self.timestamp = DateTime::from_utc( + self.timestamp = TimeZone::from_utc_datetime( // We add 946684800 to convert this to a more common Unix timestamp, // which starts on 1970, January, 1st - NaiveDateTime::from_timestamp(i64::from(timestamp) + 946_684_800, 0), - Utc, + &Utc, + #[allow(deprecated)] + &NaiveDateTime::from_timestamp(i64::from(timestamp) + 946_684_800, 0), ); } @@ -303,8 +308,8 @@ impl PPMParser { self.frame_speed = 8 - frame_speed; self.bgm_speed = 8 - bgm_speed; - self.framerate = *FRAMERATES.get(&self.frame_speed).unwrap(); - self.bgm_framerate = *FRAMERATES.get(&self.bgm_speed).unwrap(); + self.framerate = *framerates().get(&self.frame_speed).unwrap(); + self.bgm_framerate = *framerates().get(&self.bgm_speed).unwrap(); } fn frame_is_new(&mut self, index: usize) -> bool { @@ -536,33 +541,34 @@ impl PPMParser { impl Default for PPMParser { fn default() -> Self { Self { - stream: Cursor::default(), - layers: Vec::new(), - prev_layers: Vec::new(), - prev_frame_index: Default::default(), + stream: Cursor::default(), + layers: Vec::new(), + prev_layers: Vec::new(), + prev_frame_index: Default::default(), animation_data_size: Default::default(), - sound_data_size: Default::default(), - frame_count: Default::default(), - lock: Default::default(), - thumb_index: Default::default(), - root_author_name: String::default(), - parent_author_name: String::default(), + sound_data_size: Default::default(), + frame_count: Default::default(), + lock: Default::default(), + thumb_index: Default::default(), + root_author_name: String::default(), + parent_author_name: String::default(), current_author_name: String::default(), - parent_author_id: String::default(), - current_author_id: String::default(), - parent_filename: String::default(), - current_filename: String::default(), - root_author_id: String::default(), - partial_filename: String::default(), - timestamp: DateTime::from_utc(NaiveDateTime::from_timestamp(0, 0), Utc), - layer_1_visible: Default::default(), - layer_2_visible: Default::default(), - loop_: Default::default(), - frame_speed: Default::default(), - bgm_speed: Default::default(), - framerate: Default::default(), - bgm_framerate: Default::default(), - offset_table: Vec::default(), + parent_author_id: String::default(), + current_author_id: String::default(), + parent_filename: String::default(), + current_filename: String::default(), + root_author_id: String::default(), + partial_filename: String::default(), + #[allow(deprecated)] + timestamp: TimeZone::from_utc_datetime(&Utc, &NaiveDateTime::from_timestamp(0, 0)), + layer_1_visible: Default::default(), + layer_2_visible: Default::default(), + loop_: Default::default(), + frame_speed: Default::default(), + bgm_speed: Default::default(), + framerate: Default::default(), + bgm_framerate: Default::default(), + offset_table: Vec::default(), } } } -- cgit v1.2.3