really basic implementation of rpl types
This commit is contained in:
parent
b4d48a598a
commit
f046393af8
6 changed files with 201 additions and 10 deletions
|
@ -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"
|
||||
|
|
41
crates/rpl/src/instructions/mod.rs
Normal file
41
crates/rpl/src/instructions/mod.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod read;
|
||||
pub mod write;
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub enum Instruction {
|
||||
Read(read::Read),
|
||||
Write(write::Write),
|
||||
Math(MathInstruction),
|
||||
Blend(BlendInstruction),
|
||||
Noise(NoiseInstruction),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub enum MathInstruction {
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub enum BlendInstruction {
|
||||
Normal,
|
||||
Multiply,
|
||||
Additive,
|
||||
Overlay,
|
||||
Screen,
|
||||
Subtractive,
|
||||
Difference,
|
||||
Darken,
|
||||
Lighten,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub enum NoiseInstruction {
|
||||
Perlin,
|
||||
Simplex,
|
||||
Voronoi,
|
||||
}
|
19
crates/rpl/src/instructions/read.rs
Normal file
19
crates/rpl/src/instructions/read.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub struct Read {
|
||||
pub source: SourceType,
|
||||
pub format: SourceFormat,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub enum SourceType {
|
||||
File(PathBuf),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub enum SourceFormat {
|
||||
Jpeg,
|
||||
Png,
|
||||
}
|
19
crates/rpl/src/instructions/write.rs
Normal file
19
crates/rpl/src/instructions/write.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub struct Write {
|
||||
pub target: TargetType,
|
||||
pub format: TargetFormat,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub enum TargetType {
|
||||
File(PathBuf),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub enum TargetFormat {
|
||||
Jpeg,
|
||||
Png,
|
||||
}
|
|
@ -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<Instruction>);
|
||||
|
||||
#[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
|
||||
})
|
||||
])
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue