hard-rewrite #1

Merged
schrottkatze merged 6 commits from :hard-rewrite into main 2024-01-01 22:36:43 +00:00
6 changed files with 201 additions and 10 deletions
Showing only changes of commit f046393af8 - Show all commits

86
Cargo.lock generated
View file

@ -2,6 +2,21 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 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]] [[package]]
name = "executor" name = "executor"
version = "0.1.0" version = "0.1.0"
@ -10,6 +25,77 @@ version = "0.1.0"
name = "pl-cli" name = "pl-cli"
version = "0.1.0" 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]] [[package]]
name = "rpl" name = "rpl"
version = "0.1.0" 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"

View file

@ -6,3 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
serde = { version = "1.0.193", features = [ "derive" ] }
ron = "0.8"

View 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,
}

View 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,
}

View 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,
}

View file

@ -1,14 +1,38 @@
pub fn add(left: usize, right: usize) -> usize { use instructions::Instruction;
left + right 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)] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
mod tests { pub struct Rpl(Vec<Instruction>);
use super::*;
#[test] #[test]
fn it_works() { fn test_simple_deserialize() {
let result = add(2, 2); const TEST_DATA: &str =
assert_eq!(result, 4); "([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
})
])
);
} }