Skip to content

Commit 32293c3

Browse files
author
robo9k
committed
Derive Clone for structs with Copy as well
1 parent 8c08441 commit 32293c3

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/instructions.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::num::{FromPrimitive, ToPrimitive};
55
/// A register index/name
66
///
77
/// There are 16 data registers, `V0`..`VF`
8-
#[derive(FromPrimitive, Copy, Debug)]
8+
#[derive(FromPrimitive, Clone, Copy, Debug)]
99
pub enum Register {
1010
V0 = 0x0,
1111
V1 = 0x1,
@@ -48,7 +48,7 @@ pub type Byte = u8;
4848
/// A nibble (hex digit)
4949
///
5050
/// Valid values are within `0x0` .. `0xF`.
51-
#[derive(Copy, Debug)]
51+
#[derive(Clone, Copy, Debug)]
5252
pub struct Nibble {
5353
pub bits: u8,
5454
}
@@ -63,7 +63,7 @@ impl Nibble {
6363
/// Absolute memory address
6464
///
6565
/// Valid addresses are within `0x0` .. `0xFFF`.
66-
#[derive(Copy, Debug)]
66+
#[derive(Clone, Copy, Debug)]
6767
pub struct Addr {
6868
pub bits: u16,
6969
}
@@ -79,7 +79,7 @@ impl Addr {
7979
/// Raw instruction
8080
///
8181
/// Helper around the raw bits, not necessarily a valid instruction.
82-
#[derive(Copy)]
82+
#[derive(Clone, Copy)]
8383
pub struct RawInstruction {
8484
bits: u16
8585
}
@@ -130,7 +130,7 @@ impl RawInstruction {
130130
/// High-level instruction
131131
///
132132
/// A valid instruction that can be executed as-is.
133-
#[derive(Copy,Debug)]
133+
#[derive(Clone, Copy,Debug)]
134134
pub enum Instruction {
135135
/// Jumps to machine subroutine at `Addr`.
136136
///

src/vm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ const NUM_KEYS: usize = 16;
6161
/// The virtual machine manages state like its registers,
6262
/// the RAM, stack, screen pixels, pressed keys as well as
6363
/// timers and some internal state.
64-
#[derive(Copy)]
64+
// This would require "impl<T> Clone for [T; ARBITRARY_CONSTANT] where T: Copy"
65+
// One can probably do this with a macro, but for now I'm too lazy.
66+
//#[derive(Clone, Copy)]
6567
pub struct Vm {
6668
reg: [u8; NUM_DATA_REGISTERS],
6769
i: usize,

0 commit comments

Comments
 (0)