Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Use named struct for float constants #505

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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