From 2c451b653a908c8c66473404fb5dc96e1b0846b8 Mon Sep 17 00:00:00 2001 From: Vladimir Ulogov Date: Wed, 25 Sep 2024 16:31:50 -0600 Subject: [PATCH] Dev #90 --- src/conv.rs | 11 +++++++++++ tests/conv-test.rs | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/conv.rs b/src/conv.rs index d9f3d49..3980d06 100644 --- a/src/conv.rs +++ b/src/conv.rs @@ -30,6 +30,10 @@ fn value_float_conversion(t: u16, ot: u16, val: f64) -> Result { + let mut buffer = dtoa::Buffer::new(); + return Result::Ok(Value::text_buffer(buffer.format(val).to_string())); + } LIST => { return Result::Ok(Value::from(vec![Value::from(val as f64).unwrap()]).unwrap()); } @@ -66,6 +70,10 @@ fn value_integer_conversion( let mut buffer = itoa::Buffer::new(); return Result::Ok(Value::from_string(buffer.format(val).to_string())); } + TEXTBUFFER => { + let mut buffer = itoa::Buffer::new(); + return Result::Ok(Value::text_buffer(buffer.format(val).to_string())); + } LIST => { return Result::Ok(Value::from(vec![Value::from(val as i64).unwrap()]).unwrap()); } @@ -145,6 +153,9 @@ fn value_bool_conversion(t: u16, ot: u16, val: bool) -> Result { return Result::Ok(Value::from_string(format!("{}", val))); } + TEXTBUFFER => { + return Result::Ok(Value::text_buffer(format!("{}", val))); + } LIST => { return Result::Ok(Value::from(vec![Value::from_bool(val)]).unwrap()); } diff --git a/tests/conv-test.rs b/tests/conv-test.rs index 6c9a0d5..2190970 100644 --- a/tests/conv-test.rs +++ b/tests/conv-test.rs @@ -26,6 +26,11 @@ mod tests { assert_eq!(val.cast_string().unwrap(), "42.0"); } #[test] + fn test_conv_float_textbuffer() { + let val = Value::from(42.0 as f64).unwrap().conv(TEXTBUFFER).unwrap(); + assert_eq!(val.cast_string().unwrap(), "42.0"); + } + #[test] fn test_conv_float_list_check_len() { let val = Value::from(42.0 as f64).unwrap().conv(LIST).unwrap(); assert_eq!(val.len(), 1);