Skip to content

Commit 42933b2

Browse files
committed
Silencing clippy
1 parent b842952 commit 42933b2

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

src/rust/src/decoder/mod.rs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const CCX_DTVCC_SCREENGRID_COLUMNS: u8 = 210;
2323
const CCX_DTVCC_MAX_ROWS: u8 = 15;
2424
const CCX_DTVCC_MAX_COLUMNS: u8 = 32 * 2;
2525
const CCX_DTVCC_MAX_SERVICES: usize = 63;
26-
const CCX_DTVCC_MAX_WINDOWS: usize = 8;
26+
// const CCX_DTVCC_MAX_WINDOWS: usize = 8;
2727

2828
/// Context required for processing 708 data
2929
pub struct Dtvcc<'a> {
@@ -44,18 +44,16 @@ pub struct Dtvcc<'a> {
4444

4545
impl<'a> Dtvcc<'a> {
4646
/// Create a new dtvcc context
47-
pub fn new<'b>(opts: &'b mut ccx_decoder_dtvcc_settings) -> Self {
47+
pub fn new(opts: &'_ mut ccx_decoder_dtvcc_settings) -> Self {
4848
// closely follows `dtvcc_init` at `src/lib_ccx/ccx_dtvcc.c:76`
4949

5050
let report = unsafe { opts.report.as_mut().unwrap() };
5151
report.reset_count = 0;
5252

5353
let is_active = false;
54-
let no_rollup = opts.no_rollup;
55-
let active_services_count = opts.active_services_count;
56-
let no_rollup = is_true(opts.no_rollup);
57-
let active_services_count = opts.active_services_count as u8;
58-
let services_active = opts.services_enabled.clone();
54+
let _no_rollup = is_true(opts.no_rollup);
55+
let _active_services_count = opts.active_services_count as u8;
56+
let services_active = opts.services_enabled;
5957

6058
// `dtvcc_clear_packet` does the following
6159
let packet_length = 0;
@@ -70,43 +68,47 @@ impl<'a> Dtvcc<'a> {
7068
// unlike C, here the decoders are allocated on the stack as an array.
7169
let decoders = {
7270
const INIT: Option<dtvcc_service_decoder> = None;
73-
let mut val = [INIT; CCX_DTVCC_MAX_SERVICES];
74-
75-
for i in 0..CCX_DTVCC_MAX_SERVICES {
76-
if is_false(opts.services_enabled[i]) {
77-
continue;
78-
}
71+
let mut decoders = [INIT; CCX_DTVCC_MAX_SERVICES];
72+
73+
decoders
74+
.iter_mut()
75+
.zip(opts.services_enabled)
76+
.enumerate()
77+
.for_each(|(i, (d, se))| {
78+
if is_false(se) {
79+
return;
80+
}
7981

80-
let mut decoder = dtvcc_service_decoder {
81-
// we cannot allocate this on the stack as `dtvcc_service_decoder` is a C
82-
// struct cannot be changed trivially
83-
tv: Box::into_raw(Box::new(dtvcc_tv_screen {
84-
cc_count: 0,
85-
service_number: i as i32 + 1,
86-
..dtvcc_tv_screen::default()
87-
})),
88-
..dtvcc_service_decoder::default()
89-
};
90-
91-
decoder.windows.iter_mut().for_each(|w| {
92-
w.memory_reserved = 0;
93-
});
82+
let mut decoder = dtvcc_service_decoder {
83+
// we cannot allocate this on the stack as `dtvcc_service_decoder` is a C
84+
// struct cannot be changed trivially
85+
tv: Box::into_raw(Box::new(dtvcc_tv_screen {
86+
cc_count: 0,
87+
service_number: i as i32 + 1,
88+
..dtvcc_tv_screen::default()
89+
})),
90+
..dtvcc_service_decoder::default()
91+
};
92+
93+
decoder.windows.iter_mut().for_each(|w| {
94+
w.memory_reserved = 0;
95+
});
9496

95-
unsafe { dtvcc_windows_reset(&mut decoder) };
97+
unsafe { dtvcc_windows_reset(&mut decoder) };
9698

97-
val[i] = Some(decoder);
98-
}
99+
*d = Some(decoder);
100+
});
99101

100-
val
102+
decoders
101103
};
102104

103105
let encoder = None; // Unlike C, does not mention `encoder` and is initialised to `null` by default
104106

105107
Self {
106108
report,
107109
is_active,
108-
no_rollup,
109-
active_services_count,
110+
no_rollup: _no_rollup,
111+
active_services_count: _active_services_count,
110112
services_active,
111113
packet_length,
112114
is_header_parsed,

src/rust/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub fn verify_parity(data: u8) -> bool {
135135

136136
/// Process CC data according to its type
137137
pub fn do_cb(ctx: &mut lib_cc_decode, cc_block: &[u8]) -> bool {
138-
let dtvcc: &mut Dtvcc = unsafe { std::mem::transmute(ctx.dtvcc_rust) };
138+
let dtvcc = unsafe { &mut *(ctx.dtvcc_rust as *mut decoder::Dtvcc<'_>) };
139139
let cc_valid = (cc_block[0] & 4) >> 2;
140140
let cc_type = cc_block[0] & 3;
141141
let mut timeok = true;

0 commit comments

Comments
 (0)