Skip to content

Commit

Permalink
Make PostScriptOp copyable again
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Oct 27, 2024
1 parent fd360b1 commit 9e686a2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -315,9 +315,9 @@ pub enum PostScriptOp {
Xor,

/// Conditional. Runs if boolean argument is true.
If(Vec<Self>),
If(&'a [Self]),
/// Conditional. Decides which branch to run depending on boolean argument.
IfElse(Vec<Self>, Vec<Self>),
IfElse(&'a [Self], &'a [Self]),

/// Copy the top elements. One integer argument.
Copy,
Expand All @@ -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<u8> {
let mut buf = Vec::new();
Expand Down Expand Up @@ -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 }"
);
}
}

0 comments on commit 9e686a2

Please sign in to comment.