Skip to content

Commit

Permalink
refactor!: Use named struct for float constants (#505)
Browse files Browse the repository at this point in the history
This simplifies serialisation with pydantic

---------

Co-authored-by: Alec Edgington <[email protected]>
  • Loading branch information
mark-koch and cqc-alec authored Sep 7, 2023
1 parent 71b6ff0 commit 5a97a63
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/std_extensions/arithmetic/float_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ pub const FLOAT64_TYPE: Type = Type::new_extension(FLOAT64_CUSTOM_TYPE);

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
/// A floating-point value.
pub struct ConstF64(f64);
pub struct ConstF64 {
/// The value.
value: f64,
}

impl std::ops::Deref for ConstF64 {
type Target = f64;

fn deref(&self) -> &Self::Target {
&self.0
&self.value
}
}

impl ConstF64 {
/// Create a new [`ConstF64`]
pub fn new(value: f64) -> Self {
Self(value)
Self { value }
}
}

Expand All @@ -47,7 +50,7 @@ impl KnownTypeConst for ConstF64 {
#[typetag::serde]
impl CustomConst for ConstF64 {
fn name(&self) -> SmolStr {
format!("f64({})", self.0).into()
format!("f64({})", self.value).into()
}

fn check_custom_type(&self, typ: &CustomType) -> Result<(), CustomCheckFailure> {
Expand Down

0 comments on commit 5a97a63

Please sign in to comment.