diff --git a/src/bin/gui.rs b/src/bin/gui.rs index 1be2f88..7424864 100644 --- a/src/bin/gui.rs +++ b/src/bin/gui.rs @@ -1,6 +1,6 @@ -use dust_lib::eval; -use iced::widget::{button, column, container, scrollable, text, text_input, Column, Text}; -use iced::{executor, Alignment, Application, Command, Element, Sandbox, Settings, Theme}; +use dust_lib::{eval, Value}; +use iced::widget::{column, container, text, text_input, Column}; +use iced::{executor, Application, Command, Element, Sandbox, Settings, Theme}; use once_cell::sync::Lazy; static INPUT_ID: Lazy = Lazy::new(text_input::Id::unique); @@ -69,7 +69,7 @@ impl Application for DustGui { let mut text_widgets = Vec::new(); for result in &self.results { - text_widgets.push(text(result).into()); + // text_widgets.push(text(result).style().into()); } text_widgets.reverse(); @@ -86,3 +86,7 @@ enum Message { TextInput(String), Evaluate, } + +struct DustOutput { + content: dust_lib::Result, +} diff --git a/src/error.rs b/src/error.rs index aec158e..e4950ef 100644 --- a/src/error.rs +++ b/src/error.rs @@ -293,6 +293,12 @@ impl From for Error { } } +impl From for Error { + fn from(value: toml::de::Error) -> Self { + Error::MacroFailure(value.to_string()) + } +} + impl Error { pub(crate) fn expect_operator_argument_amount(actual: usize, expected: usize) -> Result<()> { if actual == expected { diff --git a/src/tools/data_formats.rs b/src/tools/data_formats.rs index 3be6a25..066092f 100644 --- a/src/tools/data_formats.rs +++ b/src/tools/data_formats.rs @@ -2,6 +2,26 @@ use crate::{Result, Table, Tool, ToolInfo, Value, ValueType}; +pub struct FromToml; + +impl Tool for FromToml { + fn info(&self) -> ToolInfo<'static> { + ToolInfo { + identifier: "from_toml", + description: "Create a value from a TOML string.", + group: "data", + inputs: vec![ValueType::String], + } + } + + fn run(&self, argument: &Value) -> Result { + let argument = argument.as_string()?; + let value = toml::from_str(&argument)?; + + Ok(value) + } +} + pub struct FromJson; impl Tool for FromJson { diff --git a/src/value/time.rs b/src/value/time.rs index 634228c..67d66b3 100644 --- a/src/value/time.rs +++ b/src/value/time.rs @@ -10,7 +10,7 @@ use std::{ fmt::{self, Display, Formatter}, - time::{Duration, Instant, SystemTime, UNIX_EPOCH}, + time::{Instant, SystemTime}, }; use chrono::{DateTime, FixedOffset, Local as LocalTime, NaiveDateTime}; diff --git a/tests/data_formats.ds b/tests/data_formats.ds new file mode 100644 index 0000000..6264143 --- /dev/null +++ b/tests/data_formats.ds @@ -0,0 +1,4 @@ +dob = from_toml("1979-05-27T07:32:00-08:00"); +toml = to_toml(dob); + +assert_equal(toml, "1979-05-27T07:32:00-08:00"); diff --git a/tests/dust_tests.rs b/tests/dust_tests.rs index 04c5b0e..2ed4f0e 100644 --- a/tests/dust_tests.rs +++ b/tests/dust_tests.rs @@ -36,3 +36,10 @@ fn scope() { eval(&file_contents).unwrap(); } + +#[test] +fn data_formats() { + let file_contents = read_to_string("tests/data_formats.ds").unwrap(); + + eval(&file_contents).unwrap(); +}