Skip to content

Commit 0c3b357

Browse files
committed
fix(glueball): obey clippy
1 parent fd68858 commit 0c3b357

3 files changed

Lines changed: 18 additions & 39 deletions

File tree

glueball/src/room.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct Room {
2626

2727
impl Room {
2828
pub fn new_with_host(host_id: &ClientId, host_name: &str, host_tx: ClientSender) -> Self {
29-
Room {
29+
Self {
3030
members: vec![Client::new(*host_id, host_name.to_string(), host_tx)],
3131
host: Some(*host_id),
3232
locked: false,

glueball/src/state.rs

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::model::RoomInfo;
22
use crate::room::{Client, ClientId, ClientSender, Room, RoomId, RoomStatus};
33

4-
use anyhow::Result;
54
use dashmap::DashMap;
65
use dashmap::mapref::one::{Ref, RefMut};
76
use rand::RngExt;
@@ -36,7 +35,7 @@ impl State {
3635
) -> Option<(ClientId, RoomId)> {
3736
match room_id {
3837
None if self.room_count() == MAX_ROOM_COUNT => None,
39-
None => Some(self.add_room_and_host(name.to_string(), tx).ok()?),
38+
None => Some(self.add_room_and_host(name, tx)),
4039
Some(room_id) => self
4140
.add_client_to_room(name, tx, &room_id)
4241
.map(|client_id| (client_id, room_id)),
@@ -48,13 +47,9 @@ impl State {
4847
room.get_sender(client_id)
4948
}
5049

51-
pub fn add_room_and_host(
52-
&self,
53-
host_name: String,
54-
host_tx: ClientSender,
55-
) -> Result<(ClientId, RoomId)> {
50+
pub fn add_room_and_host(&self, host_name: &str, host_tx: ClientSender) -> (ClientId, RoomId) {
5651
let host_id = Uuid::new_v4();
57-
let room = Room::new_with_host(&host_id, &host_name, host_tx);
52+
let room = Room::new_with_host(&host_id, host_name, host_tx);
5853

5954
let room_id = loop {
6055
let code = generate_6_digit_code();
@@ -68,7 +63,7 @@ impl State {
6863
self.users.insert(host_id, room_id.clone());
6964
self.rooms.insert(room_id.clone(), room);
7065

71-
Ok((host_id, room_id))
66+
(host_id, room_id)
7267
}
7368

7469
/// # Safety
@@ -168,6 +163,7 @@ impl State {
168163
let mut room = self.rooms.get_mut(room_id)?;
169164
room.locked = !room.locked;
170165
let locked = room.locked;
166+
drop(room);
171167

172168
if locked {
173169
info_room!(room_id, "Room Locked");
@@ -295,9 +291,7 @@ mod tests {
295291
fn create_room_adds_host() {
296292
log_tx();
297293
let state = State::new();
298-
state
299-
.add_room_and_host("Alice".to_string(), client_tx())
300-
.unwrap();
294+
state.add_room_and_host("Alice", client_tx());
301295
assert_eq!(state.room_count(), 1);
302296

303297
let rooms = state.list_rooms();
@@ -309,9 +303,7 @@ mod tests {
309303
fn join_existing_room() {
310304
log_tx();
311305
let state = State::new();
312-
let (_, room_id) = state
313-
.add_room_and_host("Alice".to_string(), client_tx())
314-
.unwrap();
306+
let (_, room_id) = state.add_room_and_host("Alice", client_tx());
315307

316308
assert!(
317309
state
@@ -336,9 +328,7 @@ mod tests {
336328
fn join_locked_room_returns_none() {
337329
log_tx();
338330
let state = State::new();
339-
let (_, room_id) = state
340-
.add_room_and_host("Alice".to_string(), client_tx())
341-
.unwrap();
331+
let (_, room_id) = state.add_room_and_host("Alice", client_tx());
342332
state.toggle_room_lock(&room_id);
343333

344334
assert!(
@@ -352,9 +342,7 @@ mod tests {
352342
fn last_client_leaving_closes_room() {
353343
log_tx();
354344
let state = State::new();
355-
let (client_id, _) = state
356-
.add_room_and_host("Alice".to_string(), client_tx())
357-
.unwrap();
345+
let (client_id, _) = state.add_room_and_host("Alice", client_tx());
358346
state.remove_client(&client_id);
359347

360348
assert_eq!(state.room_count(), 0);
@@ -364,9 +352,7 @@ mod tests {
364352
fn host_leaving_transfers_to_next_member() {
365353
log_tx();
366354
let state = State::new();
367-
let (host_id, room_id) = state
368-
.add_room_and_host("Alice".to_string(), client_tx())
369-
.unwrap();
355+
let (host_id, room_id) = state.add_room_and_host("Alice", client_tx());
370356

371357
state
372358
.add_client_to_room("Bob", client_tx(), &room_id)
@@ -398,9 +384,7 @@ mod tests {
398384
let state = State::new();
399385
assert!(state.list_rooms().is_empty());
400386

401-
let (_, room_id) = state
402-
.add_room_and_host("Alice".to_string(), client_tx())
403-
.unwrap();
387+
let (_, room_id) = state.add_room_and_host("Alice", client_tx());
404388
state.toggle_room_lock(&room_id);
405389
let rooms = state.list_rooms();
406390

@@ -413,9 +397,7 @@ mod tests {
413397
fn toggle_lock_flips_state() {
414398
log_tx();
415399
let state = State::new();
416-
let (_, room_id) = state
417-
.add_room_and_host("Alice".to_string(), client_tx())
418-
.unwrap();
400+
let (_, room_id) = state.add_room_and_host("Alice", client_tx());
419401

420402
assert_eq!(state.toggle_room_lock(&room_id), Some(true));
421403
assert_eq!(state.toggle_room_lock(&room_id), Some(false));
@@ -426,9 +408,7 @@ mod tests {
426408
log_tx();
427409
let state = State::new();
428410
for i in 0..MAX_ROOM_COUNT {
429-
state
430-
.add_room_and_host(format!("Client{i}"), client_tx())
431-
.unwrap();
411+
state.add_room_and_host(&format!("Client{i}"), client_tx());
432412
}
433413

434414
assert!(

glueball/src/tui.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,12 @@ fn run_app(
105105
let room_logs_len = app
106106
.focused_room
107107
.clone()
108-
.map(|room_id| {
108+
.and_then(|room_id| {
109109
logger_snapshot
110110
.1
111111
.get::<str>(room_id.as_ref())
112-
.map(|logs| logs.len())
112+
.map(VecDeque::len)
113113
})
114-
.flatten()
115114
.unwrap_or(0);
116115

117116
app.on_key(
@@ -266,15 +265,15 @@ impl App {
266265
// Clamping to valid range is handled in render_logs.
267266
KeyCode::Char('[') => {
268267
self.room_log_cursor =
269-
usize::min(self.room_log_cursor + 1, room_log_len.saturating_sub(1))
268+
usize::min(self.room_log_cursor + 1, room_log_len.saturating_sub(1));
270269
}
271270
KeyCode::Char(']') => self.room_log_cursor = self.room_log_cursor.saturating_sub(1),
272271

273272
// System log cursor: { moves up (older), } moves down (newer).
274273
// Clamping to valid range is handled in render_logs.
275274
KeyCode::Char('{') => {
276275
self.system_log_cursor =
277-
usize::min(self.system_log_cursor + 1, sys_log_len.saturating_sub(1))
276+
usize::min(self.system_log_cursor + 1, sys_log_len.saturating_sub(1));
278277
}
279278
KeyCode::Char('}') => self.system_log_cursor = self.system_log_cursor.saturating_sub(1),
280279

0 commit comments

Comments
 (0)