Skip to content

Commit f6f0c1f

Browse files
axelkarids1024
authored andcommitted
fix: warnings in examples after linting them got enabled
1 parent c0263c9 commit f6f0c1f

File tree

4 files changed

+61
-83
lines changed

4 files changed

+61
-83
lines changed

examples/list-devices.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct DeviceData {
2222
}
2323

2424
impl DeviceData {
25+
#[allow(dead_code)]
2526
fn interface<T: reis::Interface>(&self) -> Option<T> {
2627
self.interfaces.get(T::NAME)?.clone().downcast()
2728
}
@@ -39,10 +40,10 @@ struct State {
3940
impl State {
4041
fn handle_event(&mut self, event: ei::Event) {
4142
match event {
42-
ei::Event::Handshake(handshake, request) => panic!(),
43-
ei::Event::Connection(connection, request) => match request {
43+
ei::Event::Handshake(_handshake, _request) => panic!(),
44+
ei::Event::Connection(_connection, request) => match request {
4445
ei::connection::Event::Seat { seat } => {
45-
self.seats.insert(seat, Default::default());
46+
self.seats.insert(seat, SeatData::default());
4647
}
4748
ei::connection::Event::Ping { ping } => {
4849
ping.done(0);
@@ -73,7 +74,7 @@ impl State {
7374
}
7475
ei::seat::Event::Device { device } => {
7576
data.devices.push(device.clone());
76-
self.devices.insert(device, Default::default());
77+
self.devices.insert(device, DeviceData::default());
7778
}
7879
_ => {}
7980
}
@@ -89,7 +90,7 @@ impl State {
8990
}
9091
ei::device::Event::Interface { object } => {
9192
data.interfaces
92-
.insert(object.interface().to_string(), object);
93+
.insert(object.interface().to_owned(), object);
9394
}
9495
ei::device::Event::Done => {
9596
data.done = true;
@@ -102,22 +103,20 @@ impl State {
102103
data.interfaces.keys().collect::<Vec<_>>()
103104
);
104105
}
105-
ei::device::Event::Resumed { serial } => {}
106106
_ => {}
107107
}
108108
}
109-
ei::Event::Callback(callback, request) => {
110-
if let ei::callback::Event::Done { callback_data: _ } = request {
111-
// TODO: Callback being called after first device, but not later ones?
112-
// self.print_and_exit_if_done();
113-
}
109+
ei::Event::Callback(_callback, ei::callback::Event::Done { .. }) => {
110+
// TODO: Callback being called after first device, but not later ones?
111+
// self.print_and_exit_if_done();
114112
}
115113
_ => {}
116114
}
117115

118116
let _ = self.context.flush();
119117
}
120118

119+
#[allow(dead_code)]
121120
fn print_and_exit_if_done(&self) {
122121
if !(self.seats.values().all(|x| x.done) && self.devices.values().all(|x| x.done)) {
123122
return;
@@ -172,10 +171,10 @@ async fn main() {
172171
while let Some(result) = events.next().await {
173172
let event = match result.unwrap() {
174173
PendingRequestResult::Request(event) => event,
175-
PendingRequestResult::ParseError(msg) => {
174+
PendingRequestResult::ParseError(_msg) => {
176175
todo!()
177176
}
178-
PendingRequestResult::InvalidObject(object_id) => {
177+
PendingRequestResult::InvalidObject(_object_id) => {
179178
// TODO
180179
continue;
181180
}

examples/receive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async fn open_connection() -> ei::Context {
3636
let x = region.x_offset();
3737
let y = region.y_offset();
3838
let w = region.width() as i32;
39-
let h = region.height() as i32;
39+
let _h = region.height() as i32;
4040
Barrier::new(NonZero::new(n as u32 + 1).unwrap(), (x, y, x + w - 1, y))
4141
})
4242
.collect::<Vec<_>>();
@@ -75,7 +75,7 @@ async fn main() {
7575
| DeviceCapability::Scroll
7676
| DeviceCapability::Button,
7777
);
78-
context.flush();
78+
let _ = context.flush();
7979
}
8080
reis::event::EiEvent::DeviceAdded(evt) => {
8181
println!(" seat: {:?}", evt.device.seat().name());

examples/reis-demo-server.rs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@ struct ContextState {
2121

2222
impl ContextState {
2323
fn disconnected(
24-
&self,
2524
connection: &Connection,
2625
reason: eis::connection::DisconnectReason,
2726
explaination: &str,
2827
) -> calloop::PostAction {
2928
connection.disconnected(reason, explaination);
30-
connection.flush();
29+
let _ = connection.flush();
3130
calloop::PostAction::Remove
3231
}
3332

34-
fn protocol_error(&self, connection: &Connection, explanation: &str) -> calloop::PostAction {
35-
self.disconnected(
33+
fn protocol_error(connection: &Connection, explanation: &str) -> calloop::PostAction {
34+
Self::disconnected(
3635
connection,
3736
eis::connection::DisconnectReason::Protocol,
3837
explanation,
@@ -112,14 +111,15 @@ struct State {
112111
}
113112

114113
impl State {
114+
#![allow(clippy::unnecessary_wraps)]
115115
fn handle_new_connection(&mut self, context: eis::Context) -> io::Result<calloop::PostAction> {
116116
println!("New connection: {context:?}");
117117

118118
let source = EisRequestSource::new(context, 1);
119119
let mut context_state = ContextState { seat: None };
120120
self.handle
121-
.insert_source(source, move |event, connected_state, state| match event {
122-
Ok(event) => Ok(state.handle_request_source_event(
121+
.insert_source(source, move |event, connected_state, _state| match event {
122+
Ok(event) => Ok(Self::handle_request_source_event(
123123
&mut context_state,
124124
connected_state,
125125
event,
@@ -128,13 +128,16 @@ impl State {
128128
if let reis::Error::Request(reis::request::RequestError::InvalidCapabilities) =
129129
err
130130
{
131-
Ok(context_state.disconnected(
131+
Ok(ContextState::disconnected(
132132
connected_state,
133133
eis::connection::DisconnectReason::Value,
134134
&err.to_string(),
135135
))
136136
} else {
137-
Ok(context_state.protocol_error(connected_state, &err.to_string()))
137+
Ok(ContextState::protocol_error(
138+
connected_state,
139+
&err.to_string(),
140+
))
138141
}
139142
}
140143
})
@@ -143,28 +146,7 @@ impl State {
143146
Ok(calloop::PostAction::Continue)
144147
}
145148

146-
fn connected(&mut self, connection: &Connection) {
147-
if !connection.has_interface("ei_seat") || !connection.has_interface("ei_device") {
148-
connection.disconnected(
149-
eis::connection::DisconnectReason::Protocol,
150-
"Need `ei_seat` and `ei_device`",
151-
);
152-
connection.flush();
153-
}
154-
155-
let _seat = connection.add_seat(
156-
Some("default"),
157-
DeviceCapability::Pointer
158-
| DeviceCapability::PointerAbsolute
159-
| DeviceCapability::Keyboard
160-
| DeviceCapability::Touch
161-
| DeviceCapability::Scroll
162-
| DeviceCapability::Button,
163-
);
164-
}
165-
166149
fn handle_request_source_event(
167-
&mut self,
168150
context_state: &mut ContextState,
169151
connection: &Connection,
170152
event: EisRequestSourceEvent,
@@ -176,7 +158,7 @@ impl State {
176158
eis::connection::DisconnectReason::Protocol,
177159
"Need `ei_seat` and `ei_device`",
178160
);
179-
connection.flush();
161+
let _ = connection.flush();
180162
}
181163

182164
let seat = connection.add_seat(
@@ -205,7 +187,7 @@ impl State {
205187
}
206188
}
207189

208-
connection.flush();
190+
let _ = connection.flush();
209191

210192
calloop::PostAction::Continue
211193
}
@@ -216,7 +198,7 @@ fn main() {
216198
let handle = event_loop.handle();
217199

218200
let path = reis::default_socket_path().unwrap();
219-
std::fs::remove_file(&path); // XXX in use?
201+
let _ = std::fs::remove_file(&path); // XXX in use?
220202
let listener = eis::Listener::bind(&path).unwrap();
221203
let listener_source = EisListenerSource::new(listener);
222204
handle

examples/type-text.rs

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct State {
5252
}
5353

5454
impl State {
55+
#![allow(clippy::unnecessary_wraps, clippy::too_many_lines)]
5556
fn handle_listener_readable(
5657
&mut self,
5758
context: &mut ei::Context,
@@ -63,10 +64,10 @@ impl State {
6364
while let Some(result) = context.pending_event() {
6465
let request = match result {
6566
PendingRequestResult::Request(request) => request,
66-
PendingRequestResult::ParseError(msg) => {
67+
PendingRequestResult::ParseError(_msg) => {
6768
todo!()
6869
}
69-
PendingRequestResult::InvalidObject(object_id) => {
70+
PendingRequestResult::InvalidObject(_object_id) => {
7071
// TODO
7172
continue;
7273
}
@@ -82,10 +83,6 @@ impl State {
8283
}
8384
handshake.finish();
8485
}
85-
ei::handshake::Event::InterfaceVersion {
86-
name: _,
87-
version: _,
88-
} => {}
8986
ei::handshake::Event::Connection {
9087
connection: _,
9188
serial,
@@ -94,9 +91,9 @@ impl State {
9491
}
9592
_ => {}
9693
},
97-
ei::Event::Connection(connection, request) => match request {
94+
ei::Event::Connection(_connection, request) => match request {
9895
ei::connection::Event::Seat { seat } => {
99-
self.seats.insert(seat, Default::default());
96+
self.seats.insert(seat, SeatData::default());
10097
}
10198
ei::connection::Event::Ping { ping } => {
10299
ping.done(0);
@@ -117,7 +114,7 @@ impl State {
117114
// XXX
118115
}
119116
ei::seat::Event::Device { device } => {
120-
self.devices.insert(device, Default::default());
117+
self.devices.insert(device, DeviceData::default());
121118
}
122119
_ => {}
123120
}
@@ -133,7 +130,7 @@ impl State {
133130
}
134131
ei::device::Event::Interface { object } => {
135132
data.interfaces
136-
.insert(object.interface().to_string(), object);
133+
.insert(object.interface().to_owned(), object);
137134
}
138135
ei::device::Event::Done => {
139136
if let Some(keyboard) = data.interface::<ei::Keyboard>() {
@@ -194,37 +191,37 @@ impl State {
194191
_ => {}
195192
}
196193
}
197-
ei::Event::Keyboard(keyboard, request) => {
198-
if let ei::keyboard::Event::Keymap {
199-
keymap_type,
194+
ei::Event::Keyboard(
195+
_keyboard,
196+
ei::keyboard::Event::Keymap {
197+
keymap_type: _,
200198
size,
201199
keymap,
202-
} = request
203-
{
204-
// XXX format
205-
// flags?
206-
// handle multiple keyboard?
207-
let context = xkb::Context::new(0);
208-
self.keymap = Some(
209-
unsafe {
210-
xkb::Keymap::new_from_fd(
211-
&context,
212-
keymap,
213-
size as _,
214-
xkb::KEYMAP_FORMAT_TEXT_V1,
215-
0,
216-
)
217-
}
218-
.unwrap()
219-
.unwrap(),
220-
);
221-
}
200+
},
201+
) => {
202+
// XXX format
203+
// flags?
204+
// handle multiple keyboard?
205+
let context = xkb::Context::new(0);
206+
self.keymap = Some(
207+
unsafe {
208+
xkb::Keymap::new_from_fd(
209+
&context,
210+
keymap,
211+
size as _,
212+
xkb::KEYMAP_FORMAT_TEXT_V1,
213+
0,
214+
)
215+
}
216+
.unwrap()
217+
.unwrap(),
218+
);
222219
}
223220
_ => {}
224221
}
225222
}
226223

227-
context.flush();
224+
let _ = context.flush();
228225

229226
Ok(calloop::PostAction::Continue)
230227
}
@@ -259,8 +256,8 @@ fn main() {
259256

260257
let context = futures_executor::block_on(open_connection());
261258
// XXX wait for server version?
262-
let handshake = context.handshake();
263-
context.flush();
259+
let _handshake = context.handshake();
260+
let _ = context.flush();
264261
let context_source = Generic::new(context, calloop::Interest::READ, calloop::Mode::Level);
265262
handle
266263
.insert_source(context_source, |_event, context, state: &mut State| {

0 commit comments

Comments
 (0)