Skip to content

Commit

Permalink
Make postscript op owned
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Oct 27, 2024
1 parent 46afbac commit 0349ea1
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ impl<'a> PostScriptFunction<'a> {
deref!('a, PostScriptFunction<'a> => Stream<'a>, stream);

/// PostScript operators for use in Type 4 functions.
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum PostScriptOp<'a> {
#[derive(Debug, Clone, PartialEq)]
pub enum PostScriptOp {
/// Push a real number.
Real(f32),
/// Push an integer number.
Expand Down Expand Up @@ -315,9 +315,9 @@ pub enum PostScriptOp<'a> {
Xor,

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

/// Copy the top elements. One integer argument.
Copy,
Expand All @@ -333,7 +333,7 @@ pub enum PostScriptOp<'a> {
Roll,
}

impl<'a> PostScriptOp<'a> {
impl PostScriptOp {
/// Encode a slice of operations into a byte stream.
pub fn encode(ops: &[Self]) -> Vec<u8> {
let mut buf = Vec::new();
Expand All @@ -357,18 +357,18 @@ impl<'a> PostScriptOp<'a> {
}

fn write(&self, buf: &mut Vec<u8>) {
match *self {
Self::Real(r) => buf.push_decimal(r),
Self::Integer(i) => buf.push_val(i),
match self {
Self::Real(r) => buf.push_decimal(*r),
Self::Integer(i) => buf.push_val(*i),
Self::If(ops) => {
Self::write_slice(ops, buf);
Self::write_slice(&ops, buf);
buf.push(b'\n');
buf.extend(self.operator());
}
Self::IfElse(ops1, ops2) => {
Self::write_slice(ops1, buf);
Self::write_slice(&ops1, buf);
buf.push(b'\n');
Self::write_slice(ops2, buf);
Self::write_slice(&ops2, buf);
buf.push(b'\n');
buf.extend(self.operator());
}
Expand Down Expand Up @@ -441,7 +441,7 @@ mod tests {
Dup,
Real(0.0),
Ge,
IfElse(&[Real(1.0), Add], &[Neg]),
IfElse(vec![Real(1.0), Add], vec![Neg]),
Add,
];

Expand Down

0 comments on commit 0349ea1

Please sign in to comment.