Skip to content

Commit

Permalink
refact ser/de trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Lzzzzzt committed Jan 5, 2024
1 parent d91a382 commit 549333a
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 22 deletions.
2 changes: 1 addition & 1 deletion core/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/src/date/day.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 2 additions & 1 deletion core/src/date/parser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
date::{Date, Day, Month, Year},
error::FendError, result::FendCoreResult,
error::FendError,
result::FendCoreResult,
};
use std::convert;

Expand Down
10 changes: 3 additions & 7 deletions core/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/num/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion core/src/num/continued_fraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
6 changes: 1 addition & 5 deletions core/src/num/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,7 @@ impl Value {
self.value.equals_int(0)
}

pub(crate) fn new_die<I: Interrupt>(
count: u32,
faces: u32,
int: &I,
) -> FendCoreResult<Self> {
pub(crate) fn new_die<I: Interrupt>(count: u32, faces: u32, int: &I) -> FendCoreResult<Self> {
Ok(Self::new(Dist::new_die(count, faces, int)?, vec![]))
}

Expand Down
6 changes: 1 addition & 5 deletions core/src/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,7 @@ fn expr_unit<I: Interrupt>(
})
}

fn construct_prefixed_unit<I: Interrupt>(
a: UnitDef,
b: UnitDef,
int: &I,
) -> FendCoreResult<Value> {
fn construct_prefixed_unit<I: Interrupt>(a: UnitDef, b: UnitDef, int: &I) -> FendCoreResult<Value> {
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(
Expand Down

0 comments on commit 549333a

Please sign in to comment.