iowo/crates/rpl/src/lib.rs

47 lines
1.3 KiB
Rust
Raw Normal View History

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")
2023-12-13 17:13:43 +00:00
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
2024-01-01 06:30:04 +00:00
pub struct Rpl(pub Vec<Instruction>);
2024-01-11 11:03:43 +00:00
#[cfg(test)]
mod tests {
use super::*;
use crate::instructions::{
read::{SourceFormat, SourceType},
write::{TargetFormat, TargetType},
MathInstruction,
};
2023-12-13 17:13:43 +00:00
2024-01-11 11:03:43 +00:00
#[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
})
])
);
}
2023-12-13 17:13:43 +00:00
}