Skip to content

Commit 0efe4ff

Browse files
authored
Merge pull request #1 from Lancern/master
Implememt Debug trait for the Packet enum
2 parents d88eac3 + d6f9f95 commit 0efe4ff

19 files changed

+86
-42
lines changed

src/packet/cbr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_cbr, pt_packet_type_ppt_cbr};
22

33
/// A CBR packet.
44
/// Packet: cbr
5-
#[derive(Clone, Copy)]
5+
#[derive(Clone, Copy, Debug)]
66
pub struct Cbr (pt_packet_cbr);
77
impl Cbr {
88
#[inline]
@@ -18,4 +18,4 @@ impl Cbr {
1818
}
1919

2020
wrap2raw!(Cbr, pt_packet_type_ppt_cbr, cbr);
21-
raw2wrap!(Cbr, Cbr, pt_packet_cbr);
21+
raw2wrap!(Cbr, Cbr, pt_packet_cbr);

src/packet/cyc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_cyc, pt_packet_type_ppt_cyc};
22

33
/// A CYC packet.
44
/// Packet: cyc
5-
#[derive(Clone, Copy)]
5+
#[derive(Clone, Copy, Debug)]
66
pub struct Cyc (pt_packet_cyc);
77
impl Cyc {
88
#[inline]
@@ -18,4 +18,4 @@ impl Cyc {
1818
}
1919

2020
wrap2raw!(Cyc, pt_packet_type_ppt_cyc, cyc);
21-
raw2wrap!(Cyc, Cyc, pt_packet_cyc);
21+
raw2wrap!(Cyc, Cyc, pt_packet_cyc);

src/packet/invalid.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use libipt_sys::pt_packet;
22

3-
#[derive(Clone, Copy)]
3+
#[derive(Clone, Copy, Debug)]
44
pub struct Invalid {}
55

66
impl Into<Invalid> for pt_packet {
77
fn into(self) -> Invalid { Invalid{} }
8-
}
8+
}

src/packet/ip.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use libipt_sys::{
1515
};
1616

1717
/// The IP compression
18-
#[derive(Clone, Copy, TryFromPrimitive, IntoPrimitive)]
18+
#[derive(Clone, Copy, Debug, TryFromPrimitive, IntoPrimitive)]
1919
#[repr(i32)]
2020
pub enum Compression {
2121
/// No payload. The IP has been suppressed
@@ -39,7 +39,7 @@ pub enum Compression {
3939

4040
/// A packet with IP payload.
4141
/// Packet: tip
42-
#[derive(Clone, Copy)]
42+
#[derive(Clone, Copy, Debug)]
4343
pub struct Tip (pt_packet_ip);
4444
impl Tip {
4545
#[inline]
@@ -71,7 +71,7 @@ impl Tip {
7171

7272
/// A packet with IP payload.
7373
/// Packet: fup
74-
#[derive(Clone, Copy)]
74+
#[derive(Clone, Copy, Debug)]
7575
pub struct Fup (pt_packet_ip);
7676
impl Fup {
7777
#[inline]
@@ -103,7 +103,7 @@ impl Fup {
103103

104104
/// A packet with IP payload.
105105
/// Packet: tip.pge
106-
#[derive(Clone, Copy)]
106+
#[derive(Clone, Copy, Debug)]
107107
pub struct TipPge (pt_packet_ip);
108108
impl TipPge {
109109
#[inline]
@@ -135,7 +135,7 @@ impl TipPge {
135135

136136
/// A packet with IP payload.
137137
/// Packet: tip.pgd
138-
#[derive(Clone, Copy)]
138+
#[derive(Clone, Copy, Debug)]
139139
pub struct TipPgd (pt_packet_ip);
140140
impl TipPgd {
141141
#[inline]
@@ -175,4 +175,4 @@ wrap2raw!(TipPge, pt_packet_type_ppt_tip_pge, ip);
175175
raw2wrap!(TipPge, TipPge, pt_packet_ip);
176176

177177
wrap2raw!(TipPgd, pt_packet_type_ppt_tip_pgd, ip);
178-
raw2wrap!(TipPgd, TipPgd, pt_packet_ip);
178+
raw2wrap!(TipPgd, TipPgd, pt_packet_ip);

src/packet/mnt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_mnt, pt_packet_type_ppt_mnt};
22

33
/// A MNT packet.
44
/// Packet: mnt
5-
#[derive(Clone, Copy)]
5+
#[derive(Clone, Copy, Debug)]
66
pub struct Mnt (pt_packet_mnt);
77
impl Mnt {
88
#[inline]
@@ -18,4 +18,4 @@ impl Mnt {
1818
}
1919

2020
wrap2raw!(Mnt, pt_packet_type_ppt_mnt, mnt);
21-
raw2wrap!(Mnt, Mnt, pt_packet_mnt);
21+
raw2wrap!(Mnt, Mnt, pt_packet_mnt);

src/packet/mod.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt::{Debug, Formatter};
2+
13
use libipt_sys::{
24
pt_packet,
35
pt_packet_type_ppt_cbr as PT_PACKET_TYPE_PPT_CBR,
@@ -139,6 +141,40 @@ pub enum Packet<T> {
139141
Ptw(ptw::Ptw)
140142
}
141143

144+
impl<T> Debug for Packet<T> {
145+
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
146+
match self {
147+
Self::Invalid(pack) => f.write_fmt(format_args!("Invalid({:?})", pack)),
148+
Self::Psbend(pack) => f.write_fmt(format_args!("Psbend({:?})", pack)),
149+
Self::Stop(pack) => f.write_fmt(format_args!("Stop({:?})", pack)),
150+
Self::Pad(pack) => f.write_fmt(format_args!("Pad({:?})", pack)),
151+
Self::Psb(pack) => f.write_fmt(format_args!("Psb({:?})", pack)),
152+
Self::Ovf(pack) => f.write_fmt(format_args!("Ovf({:?})", pack)),
153+
Self::Unknown(_) => f.write_str("Unknown"),
154+
Self::Fup(pack) => f.write_fmt(format_args!("Fup({:?})", pack)),
155+
Self::Tip(pack) => f.write_fmt(format_args!("Tip({:?})", pack)),
156+
Self::TipPge(pack) => f.write_fmt(format_args!("TipPge({:?})", pack)),
157+
Self::TipPgd(pack) => f.write_fmt(format_args!("TipPgd({:?})", pack)),
158+
Self::Tnt8(pack) => f.write_fmt(format_args!("Tnt8({:?})", pack)),
159+
Self::Tnt64(pack) => f.write_fmt(format_args!("Tnt64({:?})", pack)),
160+
Self::Mode(pack) => f.write_fmt(format_args!("Mode({:?})", pack)),
161+
Self::Pip(pack) => f.write_fmt(format_args!("Pip({:?})", pack)),
162+
Self::Vmcs(pack) => f.write_fmt(format_args!("Vmcs({:?})", pack)),
163+
Self::Cbr(pack) => f.write_fmt(format_args!("Cbr({:?})", pack)),
164+
Self::Tsc(pack) => f.write_fmt(format_args!("Tsc({:?})", pack)),
165+
Self::Tma(pack) => f.write_fmt(format_args!("Tma({:?})", pack)),
166+
Self::Mtc(pack) => f.write_fmt(format_args!("Mtc({:?})", pack)),
167+
Self::Cyc(pack) => f.write_fmt(format_args!("Cyc({:?})", pack)),
168+
Self::Mnt(pack) => f.write_fmt(format_args!("Mnt({:?})", pack)),
169+
Self::Exstop(pack) => f.write_fmt(format_args!("Exstop({:?})", pack)),
170+
Self::Mwait(pack) => f.write_fmt(format_args!("Mwait({:?})", pack)),
171+
Self::Pwre(pack) => f.write_fmt(format_args!("Pwre({:?})", pack)),
172+
Self::Pwrx(pack) => f.write_fmt(format_args!("Pwrx({:?})", pack)),
173+
Self::Ptw(pack) => f.write_fmt(format_args!("Ptw({:?})", pack)),
174+
}
175+
}
176+
}
177+
142178
impl<T> From<pt_packet> for Packet<T> {
143179
fn from(pkt: pt_packet) -> Self {
144180
unsafe {
@@ -174,4 +210,4 @@ impl<T> From<pt_packet> for Packet<T> {
174210
}
175211
}
176212
}
177-
}
213+
}

src/packet/mode.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt::{Debug, Formatter};
2+
13
use bitflags::bitflags;
24
use libipt_sys::{
35
pt_mode_leaf_pt_mol_exec as PT_MODE_LEAF_PT_MOL_EXEC,
@@ -107,7 +109,13 @@ impl Mode {
107109
Payload::Tsx(t) => self.0.bits = t.into()
108110
}
109111
}
110-
}
112+
}
113+
114+
impl Debug for Mode {
115+
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
116+
f.write_fmt(format_args!("Mode({{ leaf: {:?} }})", self.0.leaf))
117+
}
118+
}
111119

112120
wrap2raw!(Mode, pt_packet_type_ppt_mode, mode);
113-
raw2wrap!(Mode, Mode, pt_packet_mode);
121+
raw2wrap!(Mode, Mode, pt_packet_mode);

src/packet/mtc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_mtc, pt_packet_type_ppt_mtc};
22

33
/// A MTC packet.
44
/// Packet: mtc
5-
#[derive(Clone, Copy)]
5+
#[derive(Clone, Copy, Debug)]
66
pub struct Mtc (pt_packet_mtc);
77
impl Mtc {
88
#[inline]
@@ -18,4 +18,4 @@ impl Mtc {
1818
}
1919

2020
wrap2raw!(Mtc, pt_packet_type_ppt_mtc, mtc);
21-
raw2wrap!(Mtc, Mtc, pt_packet_mtc);
21+
raw2wrap!(Mtc, Mtc, pt_packet_mtc);

src/packet/ovf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::mem;
22
use libipt_sys::{pt_packet, pt_packet_type_ppt_ovf};
33

4-
#[derive(Clone, Copy)]
4+
#[derive(Clone, Copy, Debug)]
55
pub struct Ovf {}
66

77
impl Ovf {
@@ -20,4 +20,4 @@ impl From<Ovf> for pt_packet {
2020

2121
impl Into<Ovf> for pt_packet {
2222
fn into(self) -> Ovf{ Ovf{} }
23-
}
23+
}

src/packet/pad.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::mem;
22
use libipt_sys::{pt_packet, pt_packet_type_ppt_pad};
33

4-
#[derive(Clone, Copy)]
4+
#[derive(Clone, Copy, Debug)]
55
pub struct Pad {}
66

77
impl Pad {
@@ -20,4 +20,4 @@ impl From<Pad> for pt_packet {
2020

2121
impl Into<Pad> for pt_packet {
2222
fn into(self) -> Pad { Pad{} }
23-
}
23+
}

src/packet/pip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use libipt_sys::{
66

77
/// A PIP packet.
88
/// Packet: pip
9-
#[derive(Clone, Copy)]
9+
#[derive(Clone, Copy, Debug)]
1010
pub struct Pip (pt_packet_pip);
1111
impl Pip {
1212
#[inline]
@@ -34,4 +34,4 @@ impl Pip {
3434
}
3535

3636
wrap2raw!(Pip, pt_packet_type_ppt_pip, pip);
37-
raw2wrap!(Pip, Pip, pt_packet_pip);
37+
raw2wrap!(Pip, Pip, pt_packet_pip);

src/packet/psb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::mem;
22
use libipt_sys::{pt_packet, pt_packet_type_ppt_psb};
33

4-
#[derive(Clone, Copy)]
4+
#[derive(Clone, Copy, Debug)]
55
pub struct Psb {}
66

77
impl Psb {
@@ -20,4 +20,4 @@ impl From<Psb> for pt_packet {
2020

2121
impl Into<Psb> for pt_packet {
2222
fn into(self) -> Psb { Psb{} }
23-
}
23+
}

src/packet/psbend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::mem;
22
use libipt_sys::{pt_packet, pt_packet_type_ppt_psbend};
33

4-
#[derive(Clone, Copy)]
4+
#[derive(Clone, Copy, Debug)]
55
pub struct Psbend {}
66

77
impl Psbend {
@@ -20,4 +20,4 @@ impl From<Psbend> for pt_packet {
2020

2121
impl Into<Psbend> for pt_packet {
2222
fn into(self) -> Psbend { Psbend{} }
23-
}
23+
}

src/packet/ptw.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use libipt_sys::{
66

77
/// A PTW packet.
88
/// Packet: ptw
9-
#[derive(Clone, Copy)]
9+
#[derive(Clone, Copy, Debug)]
1010
pub struct Ptw (pt_packet_ptw);
1111
impl Ptw {
1212
#[inline]
@@ -46,4 +46,4 @@ impl Ptw {
4646
}
4747

4848
wrap2raw!(Ptw, pt_packet_type_ppt_ptw, ptw);
49-
raw2wrap!(Ptw, Ptw, pt_packet_ptw);
49+
raw2wrap!(Ptw, Ptw, pt_packet_ptw);

src/packet/pwrx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_pwrx, pt_packet_type_ppt_pwrx};
22

33
/// A PWRX packet.
44
/// Packet: pwrx
5-
#[derive(Clone, Copy)]
5+
#[derive(Clone, Copy, Debug)]
66
pub struct Pwrx (pt_packet_pwrx);
77
impl Pwrx {
88
#[inline]
@@ -76,4 +76,4 @@ impl Pwrx {
7676
}
7777

7878
wrap2raw!(Pwrx, pt_packet_type_ppt_pwrx, pwrx);
79-
raw2wrap!(Pwrx, Pwrx, pt_packet_pwrx);
79+
raw2wrap!(Pwrx, Pwrx, pt_packet_pwrx);

src/packet/stop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::mem;
22
use libipt_sys::{pt_packet, pt_packet_type_ppt_stop};
33

4-
#[derive(Clone, Copy)]
4+
#[derive(Clone, Copy, Debug)]
55
pub struct Stop {}
66

77
impl Stop {
@@ -20,4 +20,4 @@ impl From<Stop> for pt_packet {
2020

2121
impl Into<Stop> for pt_packet {
2222
fn into(self) -> Stop { Stop{} }
23-
}
23+
}

src/packet/tma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_tma, pt_packet_type_ppt_tma};
22

33
/// A TMA packet.
44
/// Packet: tma
5-
#[derive(Clone, Copy)]
5+
#[derive(Clone, Copy, Debug)]
66
pub struct Tma (pt_packet_tma);
77
impl Tma {
88
#[inline]
@@ -26,4 +26,4 @@ impl Tma {
2626
}
2727

2828
wrap2raw!(Tma, pt_packet_type_ppt_tma, tma);
29-
raw2wrap!(Tma, Tma, pt_packet_tma);
29+
raw2wrap!(Tma, Tma, pt_packet_tma);

src/packet/tnt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use libipt_sys::{
66

77
/// A TNT-8 packet.
88
/// Packet: tnt-8
9-
#[derive(Clone, Copy)]
9+
#[derive(Clone, Copy, Debug)]
1010
pub struct Tnt8 (pt_packet_tnt);
1111
impl Tnt8 {
1212
#[inline]
@@ -32,7 +32,7 @@ impl Tnt8 {
3232

3333
/// A TNT-64 packet.
3434
/// Packet: tnt-64
35-
#[derive(Clone, Copy)]
35+
#[derive(Clone, Copy, Debug)]
3636
pub struct Tnt64 (pt_packet_tnt);
3737
impl Tnt64 {
3838
#[inline]
@@ -60,4 +60,4 @@ wrap2raw!(Tnt8, pt_packet_type_ppt_tnt_8, tnt);
6060
raw2wrap!(Tnt8, Tnt8, pt_packet_tnt);
6161

6262
wrap2raw!(Tnt64, pt_packet_type_ppt_tnt_64, tnt);
63-
raw2wrap!(Tnt64, Tnt64, pt_packet_tnt);
63+
raw2wrap!(Tnt64, Tnt64, pt_packet_tnt);

src/packet/tsc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_tsc, pt_packet_type_ppt_tsc};
22

33
/// A TSC packet.
44
/// Packet: tsc
5-
#[derive(Clone, Copy)]
5+
#[derive(Clone, Copy, Debug)]
66
pub struct Tsc (pt_packet_tsc);
77
impl Tsc {
88
#[inline]
@@ -18,4 +18,4 @@ impl Tsc {
1818
}
1919

2020
wrap2raw!(Tsc, pt_packet_type_ppt_tsc, tsc);
21-
raw2wrap!(Tsc, Tsc, pt_packet_tsc);
21+
raw2wrap!(Tsc, Tsc, pt_packet_tsc);

0 commit comments

Comments
 (0)