cargo fmt

This commit is contained in:
beerpiss 2024-06-29 00:42:42 +07:00
parent 3c938c7ef3
commit 62764997ce
5 changed files with 82 additions and 79 deletions

View File

@ -6,8 +6,8 @@ use serde::{Deserialize, Serialize};
use snafu::{prelude::Snafu, ResultExt}; use snafu::{prelude::Snafu, ResultExt};
use crate::{ use crate::{
consts::USER_AGENT,
config::SaekawaConfig, config::SaekawaConfig,
consts::USER_AGENT,
types::tachi::{ types::tachi::{
api::{TachiFailureResponse, TachiResponse}, api::{TachiFailureResponse, TachiResponse},
api_returns::{ImportPollStatus, ImportResponse}, api_returns::{ImportPollStatus, ImportResponse},

View File

@ -1,71 +1,70 @@
mod music; mod music;
pub mod upsert; pub mod upsert;
use serde::{de, Deserialize}; use serde::{de, Deserialize};
pub use self::upsert::UpsertUserAllRequest; pub use self::upsert::UpsertUserAllRequest;
fn deserialize_bool<'de, D>(deserializer: D) -> Result<bool, D::Error> fn deserialize_bool<'de, D>(deserializer: D) -> Result<bool, D::Error>
where where
D: de::Deserializer<'de>, D: de::Deserializer<'de>,
{ {
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(untagged)] #[serde(untagged)]
enum BooleanishTypes { enum BooleanishTypes {
String(String), String(String),
Bool(bool), Bool(bool),
Number(i32), Number(i32),
} }
let s: BooleanishTypes = de::Deserialize::deserialize(deserializer)?; let s: BooleanishTypes = de::Deserialize::deserialize(deserializer)?;
match s { match s {
BooleanishTypes::String(s) => match s.as_str() { BooleanishTypes::String(s) => match s.as_str() {
"true" => Ok(true), "true" => Ok(true),
"false" => Ok(false), "false" => Ok(false),
_ => Err(de::Error::unknown_variant(&s, &["true", "false"])), _ => Err(de::Error::unknown_variant(&s, &["true", "false"])),
}, },
BooleanishTypes::Bool(b) => Ok(b), BooleanishTypes::Bool(b) => Ok(b),
BooleanishTypes::Number(n) => Ok(n > 0), BooleanishTypes::Number(n) => Ok(n > 0),
} }
} }
mod serde_user_play_date { mod serde_user_play_date {
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use serde::{ser, de}; use serde::{de, ser};
const DT_FORMAT: &str = "%Y-%m-%d %H:%M:%S"; const DT_FORMAT: &str = "%Y-%m-%d %H:%M:%S";
#[derive(Debug)] #[derive(Debug)]
struct UserPlayDateVisitor; struct UserPlayDateVisitor;
pub fn serialize<S>(dt: &NaiveDateTime, serializer: S) -> Result<S::Ok, S::Error> pub fn serialize<S>(dt: &NaiveDateTime, serializer: S) -> Result<S::Ok, S::Error>
where where
S: ser::Serializer, S: ser::Serializer,
{ {
serializer.serialize_str(&dt.format(DT_FORMAT).to_string()) serializer.serialize_str(&dt.format(DT_FORMAT).to_string())
} }
pub fn deserialize<'de, D>(deserializer: D) -> Result<NaiveDateTime, D::Error> pub fn deserialize<'de, D>(deserializer: D) -> Result<NaiveDateTime, D::Error>
where where
D: de::Deserializer<'de>, D: de::Deserializer<'de>,
{ {
deserializer.deserialize_str(UserPlayDateVisitor) deserializer.deserialize_str(UserPlayDateVisitor)
} }
impl<'de> de::Visitor<'de> for UserPlayDateVisitor { impl<'de> de::Visitor<'de> for UserPlayDateVisitor {
type Value = NaiveDateTime; type Value = NaiveDateTime;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(formatter, "a string in the format of \"{}\"", DT_FORMAT) write!(formatter, "a string in the format of \"{}\"", DT_FORMAT)
} }
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where where
E: de::Error, E: de::Error,
{ {
NaiveDateTime::parse_from_str(v, DT_FORMAT) NaiveDateTime::parse_from_str(v, DT_FORMAT).map_err(E::custom)
.map_err(E::custom) }
} }
} }
}

View File

@ -26,7 +26,7 @@ pub struct UserData {
#[serde( #[serde(
default = "default_class_emblem", default = "default_class_emblem",
deserialize_with = "deserialize_option_number_from_string", deserialize_with = "deserialize_option_number_from_string"
)] )]
pub class_emblem_base: Option<u32>, pub class_emblem_base: Option<u32>,

View File

@ -58,7 +58,9 @@ impl UserPlaylog {
}; };
let jst_offset = FixedOffset::east_opt(9 * 3600).expect("chrono should parse JST timezone"); let jst_offset = FixedOffset::east_opt(9 * 3600).expect("chrono should parse JST timezone");
let jst_time = jst_offset.from_local_datetime(&self.user_play_date).unwrap(); let jst_time = jst_offset
.from_local_datetime(&self.user_play_date)
.unwrap();
Ok(BatchManualScore { Ok(BatchManualScore {
score: self.score, score: self.score,

View File

@ -18,7 +18,8 @@ use winapi::{
minwindef::{BOOL, DWORD, HMODULE, LPVOID, PROC}, minwindef::{BOOL, DWORD, HMODULE, LPVOID, PROC},
ntdef::{LPCWSTR, LPSTR}, ntdef::{LPCWSTR, LPSTR},
winerror::{ winerror::{
CERT_E_CHAINING, CERT_E_EXPIRED, CERT_E_UNTRUSTEDROOT, CRYPT_E_SECURITY_SETTINGS, TRUST_E_BAD_DIGEST, TRUST_E_EXPLICIT_DISTRUST, TRUST_E_NOSIGNATURE CERT_E_CHAINING, CERT_E_EXPIRED, CERT_E_UNTRUSTEDROOT, CRYPT_E_SECURITY_SETTINGS,
TRUST_E_BAD_DIGEST, TRUST_E_EXPLICIT_DISTRUST, TRUST_E_NOSIGNATURE,
}, },
}, },
um::{ um::{
@ -172,9 +173,7 @@ struct UpdateInformation {
/// and the hook should uninject itself so a newer version can load in. /// and the hook should uninject itself so a newer version can load in.
#[allow(clippy::result_large_err)] #[allow(clippy::result_large_err)]
pub fn self_update(module: &LibraryHandle) -> Result<bool, SelfUpdateError> { pub fn self_update(module: &LibraryHandle) -> Result<bool, SelfUpdateError> {
let agent = ureq::builder() let agent = ureq::builder().user_agent(USER_AGENT).build();
.user_agent(USER_AGENT)
.build();
info!("Checking for updates..."); info!("Checking for updates...");
let response = agent let response = agent
@ -371,7 +370,10 @@ pub fn self_update(module: &LibraryHandle) -> Result<bool, SelfUpdateError> {
let handle = CreateThread( let handle = CreateThread(
ptr::null_mut(), ptr::null_mut(),
0, 0,
Some(std::mem::transmute::<PROC, unsafe extern "system" fn(*mut winapi::ctypes::c_void) -> u32>(updater_start_address)), Some(std::mem::transmute::<
PROC,
unsafe extern "system" fn(*mut winapi::ctypes::c_void) -> u32,
>(updater_start_address)),
heap as *mut _, heap as *mut _,
0, 0,
ptr::null_mut(), ptr::null_mut(),