Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 4d8196e

Browse files
author
Alex Helfet
committed
Changes from japaric's review.
1 parent 9651c96 commit 4d8196e

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

src/bin/itmdump.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![deny(warnings)]
2-
#![feature(conservative_impl_trait)]
32

43
extern crate chrono;
54
extern crate clap;
@@ -103,9 +102,9 @@ fn run() -> Result<()> {
103102
let p = decoder.read_packet();
104103
match p {
105104
Ok(p) => {
106-
match p.kind {
107-
packet::Kind::Instrumentation(ref ud) if ud.port == port => {
108-
stdout.write_all(&ud.payload)?;
105+
match p.kind() {
106+
&packet::Kind::Instrumentation(ref i) if i.port() == port => {
107+
stdout.write_all(&i.payload())?;
109108
}
110109
_ => (),
111110
}
@@ -139,7 +138,7 @@ fn run() -> Result<()> {
139138
// Unreachable.
140139
}
141140

142-
fn open_read<'a>(matches: &ArgMatches) -> Result<impl io::Read + 'a> {
141+
fn open_read(matches: &ArgMatches) -> Result<Box<io::Read + 'static>> {
143142
let path = matches.value_of("file");
144143
Ok(match path {
145144
Some(path) => {

src/packet.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,22 @@ pub const MAX_PAYLOAD_SIZE: usize = 4;
99
#[derive(Debug)]
1010
pub struct Packet {
1111
/// The header byte received for this packet.
12-
pub header: u8,
12+
pub(crate) header: u8,
1313

1414
/// The kind (type) of this packet.
15-
pub kind: Kind,
15+
pub(crate) kind: Kind,
16+
}
17+
18+
impl Packet {
19+
/// Returns the header byte received for this packet.
20+
pub fn header(&self) -> u8 {
21+
self.header
22+
}
23+
24+
/// The kind (type) of this packet.
25+
pub fn kind(&self) -> &Kind {
26+
&self.kind
27+
}
1628
}
1729

1830
/// The type of a packet.
@@ -30,10 +42,22 @@ pub enum Kind {
3042
/// Contents of an Instrumentation packet, with data from a software application
3143
pub struct Instrumentation {
3244
/// Data in this packet.
33-
pub payload: HVec<u8, [u8; MAX_PAYLOAD_SIZE]>,
45+
pub(crate) payload: HVec<u8, [u8; MAX_PAYLOAD_SIZE]>,
3446

3547
/// Stimulus port this packet was sent from.
36-
pub port: u8,
48+
pub(crate) port: u8,
49+
}
50+
51+
impl Instrumentation {
52+
/// Data in this packet.
53+
pub fn payload(&self) -> &[u8] {
54+
&*self.payload
55+
}
56+
57+
/// Stimulus port this packet was sent from.
58+
pub fn port(&self) -> u8 {
59+
self.port
60+
}
3761
}
3862

3963
impl Debug for Instrumentation {

0 commit comments

Comments
 (0)