From 9e686a28e03905d5e06b4901ebc311bdd057712d Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> Date: Sun, 27 Oct 2024 11:28:39 +0100 Subject: [PATCH] Make PostScriptOp copyable again --- src/functions.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/functions.rs b/src/functions.rs index dc0e810..4a23a4e 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -238,7 +238,7 @@ deref!('a, PostScriptFunction<'a> => Stream<'a>, stream); /// PostScript operators for use in Type 4 functions. #[derive(Debug, Clone, PartialEq)] -pub enum PostScriptOp { +pub enum PostScriptOp<'a> { /// Push a real number. Real(f32), /// Push an integer number. @@ -315,9 +315,9 @@ pub enum PostScriptOp { Xor, /// Conditional. Runs if boolean argument is true. - If(Vec), + If(&'a [Self]), /// Conditional. Decides which branch to run depending on boolean argument. - IfElse(Vec, Vec), + IfElse(&'a [Self], &'a [Self]), /// Copy the top elements. One integer argument. Copy, @@ -333,7 +333,7 @@ pub enum PostScriptOp { Roll, } -impl PostScriptOp { +impl PostScriptOp<'_> { /// Encode a slice of operations into a byte stream. pub fn encode(ops: &[Self]) -> Vec { let mut buf = Vec::new(); @@ -441,13 +441,13 @@ mod tests { Dup, Real(0.0), Ge, - IfElse(vec![Real(1.0), Add], vec![Neg]), + IfElse(&[Real(1.0), Add], &[Neg]), Add, ]; assert_eq!( PostScriptOp::encode(&ops), - b"{\n3.0\n2.0\nmul\nexch\ndup\n0.0\nge\n{\n1.0\nadd\n}\n{neg}\nifelse\nadd\n}" + b"{ 3.0 2.0 mul exch dup 0.0 ge { 1.0 add } {neg} ifelse add }" ); } }