Skip to content

Commit

Permalink
samples: philosophers: clippy suggestions
Browse files Browse the repository at this point in the history
Simple suggestions by clippy to make the code more idiomatic Rust.

Signed-off-by: David Brown <[email protected]>
  • Loading branch information
d3zd3z committed Jan 17, 2025
1 parent 8653c0f commit f82407c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
8 changes: 2 additions & 6 deletions samples/philosophers/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,17 @@ enum Command {
}

/// This implements a single Fork on the server side for the ChannelSync.
#[derive(Default)]
enum ChannelFork {
/// The fork is free,
#[default]
Free,
/// The work is in use, nobody is waiting.
InUse,
/// The fork is in use, and someone is waiting on it.
InUseWait(Sender<()>),
}

impl Default for ChannelFork {
fn default() -> Self {
ChannelFork::Free
}
}

impl ChannelFork {
/// Attempt to aquire the work. If it is free, reply to the sender, otherwise, track them to
/// reply to them when the fork is freed up.
Expand Down
6 changes: 2 additions & 4 deletions samples/philosophers/src/dynsemsync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ pub fn dyn_semaphore_sync() -> Vec<Arc<dyn ForkSync>> {
.each_ref()
.map(|()| Arc::new(Semaphore::new(1, 1).unwrap()));

let syncers = (0..NUM_PHIL)
(0..NUM_PHIL)
.map(|_| {
let syncer = SemSync {
forks: forks.clone(),
};
let item = Box::new(syncer) as Box<dyn ForkSync>;
Arc::from(item)
})
.collect();

syncers
.collect()
}
6 changes: 2 additions & 4 deletions samples/philosophers/src/semsync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,15 @@ pub fn semaphore_sync() -> Vec<Arc<dyn ForkSync>> {
Arc::new(m.init_once((1, 1)).unwrap())
});

let syncers = (0..NUM_PHIL)
(0..NUM_PHIL)
.map(|_| {
let syncer = SemSync {
forks: forks.clone(),
};
let item = Box::new(syncer) as Box<dyn ForkSync>;
Arc::from(item)
})
.collect();

syncers
.collect()
}

kobj_define! {
Expand Down

0 comments on commit f82407c

Please sign in to comment.