From 549333a3e011851e81651bdf3e04cde6491f0b03 Mon Sep 17 00:00:00 2001 From: Lzzzt Date: Fri, 5 Jan 2024 15:20:56 +0800 Subject: [PATCH] refact ser/de trait --- core/src/date.rs | 2 +- core/src/date/day.rs | 2 +- core/src/date/parser.rs | 3 ++- core/src/lexer.rs | 10 +++------- core/src/num/base.rs | 3 ++- core/src/num/continued_fraction.rs | 2 +- core/src/num/unit.rs | 6 +----- core/src/units.rs | 6 +----- 8 files changed, 12 insertions(+), 22 deletions(-) diff --git a/core/src/date.rs b/core/src/date.rs index e8df8156..5ae6c1f0 100644 --- a/core/src/date.rs +++ b/core/src/date.rs @@ -11,7 +11,7 @@ pub(crate) use day_of_week::DayOfWeek; pub(crate) use month::Month; use year::Year; -use crate::{error::FendError, ident::Ident, value::Value, result::FendCoreResult}; +use crate::{error::FendError, ident::Ident, result::FendCoreResult, value::Value}; #[derive(Copy, Clone, Eq, PartialEq)] pub(crate) struct Date { diff --git a/core/src/date/day.rs b/core/src/date/day.rs index e08905d7..e397813d 100644 --- a/core/src/date/day.rs +++ b/core/src/date/day.rs @@ -1,6 +1,6 @@ use crate::result::FendCoreResult; -use crate::{Serialize, Deserialize}; use crate::FendError; +use crate::{Deserialize, Serialize}; use std::fmt; use std::io; diff --git a/core/src/date/parser.rs b/core/src/date/parser.rs index 8d3ea5ef..d1645868 100644 --- a/core/src/date/parser.rs +++ b/core/src/date/parser.rs @@ -1,6 +1,7 @@ use crate::{ date::{Date, Day, Month, Year}, - error::FendError, result::FendCoreResult, + error::FendError, + result::FendCoreResult, }; use std::convert; diff --git a/core/src/lexer.rs b/core/src/lexer.rs index f126dd4b..1882bc9a 100644 --- a/core/src/lexer.rs +++ b/core/src/lexer.rs @@ -303,19 +303,15 @@ fn parse_basic_number<'a, I: Interrupt>( .map_err(|_| FendError::InvalidDiceSyntax)? }; let mut face_count = 0_u32; - let ((), remaining2) = parse_integer( - remaining, - false, - base, - &mut |digit| -> FendCoreResult<()> { + let ((), remaining2) = + parse_integer(remaining, false, base, &mut |digit| -> FendCoreResult<()> { face_count = face_count .checked_mul(base.base_as_u8().into()) .ok_or(FendError::InvalidDiceSyntax)? .checked_add(digit.into()) .ok_or(FendError::InvalidDiceSyntax)?; Ok(()) - }, - )?; + })?; if dice_count == 0 || face_count == 0 { return Err(FendError::InvalidDiceSyntax); } diff --git a/core/src/num/base.rs b/core/src/num/base.rs index 7c1463c6..98f2f573 100644 --- a/core/src/num/base.rs +++ b/core/src/num/base.rs @@ -2,7 +2,8 @@ use std::{fmt, io}; use crate::{ error::FendError, - serialize::{Deserialize, Serialize}, result::FendCoreResult, + result::FendCoreResult, + serialize::{Deserialize, Serialize}, }; #[derive(Copy, Clone, PartialEq, Eq)] diff --git a/core/src/num/continued_fraction.rs b/core/src/num/continued_fraction.rs index ba4faa50..b981a04c 100644 --- a/core/src/num/continued_fraction.rs +++ b/core/src/num/continued_fraction.rs @@ -10,8 +10,8 @@ use crate::format::Format; use crate::interrupt::Never; use crate::num::bigrat::sign::Sign; use crate::num::biguint::BigUint; -use crate::Interrupt; use crate::result::FendCoreResult; +use crate::Interrupt; use std::hash::Hash; use std::rc::Rc; use std::{cmp, fmt, io, iter, mem, ops}; diff --git a/core/src/num/unit.rs b/core/src/num/unit.rs index a2d1afee..518176ac 100644 --- a/core/src/num/unit.rs +++ b/core/src/num/unit.rs @@ -456,11 +456,7 @@ impl Value { self.value.equals_int(0) } - pub(crate) fn new_die( - count: u32, - faces: u32, - int: &I, - ) -> FendCoreResult { + pub(crate) fn new_die(count: u32, faces: u32, int: &I) -> FendCoreResult { Ok(Self::new(Dist::new_die(count, faces, int)?, vec![])) } diff --git a/core/src/units.rs b/core/src/units.rs index 3d19a8ce..0265d915 100644 --- a/core/src/units.rs +++ b/core/src/units.rs @@ -139,11 +139,7 @@ fn expr_unit( }) } -fn construct_prefixed_unit( - a: UnitDef, - b: UnitDef, - int: &I, -) -> FendCoreResult { +fn construct_prefixed_unit(a: UnitDef, b: UnitDef, int: &I) -> FendCoreResult { let product = a.value.expect_num()?.mul(b.value.expect_num()?, int)?; assert_eq!(a.singular, a.plural); let unit = Number::create_unit_value_from_value(