Skip to content

Commit

Permalink
share only the bytes block
Browse files Browse the repository at this point in the history
  • Loading branch information
pront committed Dec 9, 2024
1 parent 3ff97ae commit 28a1452
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/stdlib/parse_float.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::compiler::prelude::*;
use crate::stdlib::to_float::to_float;
use crate::stdlib::to_float::{bytes_to_float};

fn parse_float(value: Value) -> Resolved {
to_float(value)
bytes_to_float(value.try_bytes()?)
}

#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -127,7 +127,7 @@ mod tests {

nan {
args: func_args![value: "Nan"],
want: Err("NaN number not supported".to_string()),
want: Err("NaN number not supported \"Nan\"".to_string()),
tdef: TypeDef::float().fallible(),
}

Expand Down
8 changes: 7 additions & 1 deletion src/stdlib/to_float.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use crate::compiler::conversion::Conversion;
use crate::compiler::prelude::*;

pub(crate) fn to_float(value: Value) -> Resolved {
pub(crate) fn bytes_to_float(bytes: Bytes) -> Resolved {
Conversion::Float
.convert(bytes)
.map_err(|e| e.to_string().into())
}

fn to_float(value: Value) -> Resolved {
use Value::{Boolean, Bytes, Float, Integer, Null, Timestamp};
match value {
Float(_) => Ok(value),
Expand Down

0 comments on commit 28a1452

Please sign in to comment.