iowo/crates/rpl/src/lib.rs

36 lines
1.1 KiB
Rust

use instructions::Instruction;
use serde::{Deserialize, Serialize};
pub mod instructions;
/// # Panics
///
/// Panics if deserialization fails. lol.
#[must_use]
pub fn from_ron(raw: &str) -> Rpl {
ron::from_str(raw).expect("come back later and handle me correctly")
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub struct Rpl(pub 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
})
])
);
}