iowo/crates/rpl/src/lib.rs

38 lines
1.1 KiB
Rust

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()
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub struct Rpl(Vec<Instruction>);
#[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
})
])
);
}