Skip to content

Commit e82dfca

Browse files
committed
samples: philosophers: clippy suggestions
Simple suggestions by clippy to make the code more idiomatic Rust. Signed-off-by: David Brown <[email protected]>
1 parent 6c4375c commit e82dfca

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

samples/philosophers/src/channel.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,17 @@ enum Command {
3232
}
3333

3434
/// This implements a single Fork on the server side for the ChannelSync.
35+
#[derive(Default)]
3536
enum ChannelFork {
3637
/// The fork is free,
38+
#[default]
3739
Free,
3840
/// The work is in use, nobody is waiting.
3941
InUse,
4042
/// The fork is in use, and someone is waiting on it.
4143
InUseWait(Sender<()>),
4244
}
4345

44-
impl Default for ChannelFork {
45-
fn default() -> Self {
46-
ChannelFork::Free
47-
}
48-
}
49-
5046
impl ChannelFork {
5147
/// Attempt to aquire the work. If it is free, reply to the sender, otherwise, track them to
5248
/// reply to them when the fork is freed up.

samples/philosophers/src/dynsemsync.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ pub fn dyn_semaphore_sync() -> Vec<Arc<dyn ForkSync>> {
3737
.each_ref()
3838
.map(|()| Arc::new(Semaphore::new(1, 1).unwrap()));
3939

40-
let syncers = (0..NUM_PHIL)
40+
(0..NUM_PHIL)
4141
.map(|_| {
4242
let syncer = SemSync {
4343
forks: forks.clone(),
4444
};
4545
let item = Box::new(syncer) as Box<dyn ForkSync>;
4646
Arc::from(item)
4747
})
48-
.collect();
49-
50-
syncers
48+
.collect()
5149
}

samples/philosophers/src/semsync.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,15 @@ pub fn semaphore_sync() -> Vec<Arc<dyn ForkSync>> {
3838
Arc::new(m.init_once((1, 1)).unwrap())
3939
});
4040

41-
let syncers = (0..NUM_PHIL)
41+
(0..NUM_PHIL)
4242
.map(|_| {
4343
let syncer = SemSync {
4444
forks: forks.clone(),
4545
};
4646
let item = Box::new(syncer) as Box<dyn ForkSync>;
4747
Arc::from(item)
4848
})
49-
.collect();
50-
51-
syncers
49+
.collect()
5250
}
5351

5452
kobj_define! {

0 commit comments

Comments
 (0)