diff --git a/Cargo.lock b/Cargo.lock index 71c3f53..83c69ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "base64" +version = "0.21.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +dependencies = [ + "serde", +] + [[package]] name = "executor" version = "0.1.0" @@ -10,6 +25,77 @@ version = "0.1.0" name = "pl-cli" version = "0.1.0" +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ron" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" +dependencies = [ + "base64", + "bitflags", + "serde", + "serde_derive", +] + [[package]] name = "rpl" version = "0.1.0" +dependencies = [ + "ron", + "serde", +] + +[[package]] +name = "serde" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/crates/rpl/Cargo.toml b/crates/rpl/Cargo.toml index e6e42c6..e406f11 100644 --- a/crates/rpl/Cargo.toml +++ b/crates/rpl/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +serde = { version = "1.0.193", features = [ "derive" ] } +ron = "0.8" diff --git a/crates/rpl/src/lib.rs b/crates/rpl/src/lib.rs index 7d12d9a..c5102f3 100644 --- a/crates/rpl/src/lib.rs +++ b/crates/rpl/src/lib.rs @@ -1,14 +1,38 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right +use instructions::Instruction; +use serde::{Deserialize, Serialize}; + +use crate::instructions::{ + read::{SourceFormat, SourceType}, + write::{TargetFormat, TargetType}, + MathInstruction, +}; + +pub mod instructions; + +pub fn from_ron(raw: &str) -> Rpl { + ron::from_str(raw).unwrap() } -#[cfg(test)] -mod tests { - use super::*; +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] +pub struct Rpl(Vec); - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } +#[test] +fn test_simple_deserialize() { + const TEST_DATA: &str = + "([Read( (source: File(\"~/example/file.png\"), format: Png) ),Math(Add),Write(( target: File(\"~/example/out.jpg\"), format: Jpeg))])"; + + assert_eq!( + from_ron(TEST_DATA), + Rpl(vec![ + Instruction::Read(instructions::read::Read { + source: SourceType::File("~/example/file.png".into()), + format: SourceFormat::Png + }), + Instruction::Math(MathInstruction::Add), + Instruction::Write(instructions::write::Write { + target: TargetType::File("~/example/out.jpg".into()), + format: TargetFormat::Jpeg + }) + ]) + ); }