Skip to content

Commit

Permalink
sound: fix some minor clippy lints
Browse files Browse the repository at this point in the history
Unnecessary lazy evaluation in Option::ok_or_else uses, constify some
functions.

Signed-off-by: Manos Pitsidianakis <[email protected]>
  • Loading branch information
epilys committed Dec 2, 2024
1 parent 937d28d commit 4ea77f5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion vhost-device-sound/src/audio_backends/alsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ impl AudioBackend for AlsaBackend {
.write()
.unwrap()
.get_mut(id as usize)
.ok_or_else(|| Error::StreamWithIdNotFound(id))?
.ok_or(Error::StreamWithIdNotFound(id))?
.state
.stop()
{
Expand Down
2 changes: 1 addition & 1 deletion vhost-device-sound/src/audio_backends/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct NullBackend {
}

impl NullBackend {
pub fn new(streams: Arc<RwLock<Vec<Stream>>>) -> Self {
pub const fn new(streams: Arc<RwLock<Vec<Stream>>>) -> Self {
Self { streams }
}
}
Expand Down
8 changes: 4 additions & 4 deletions vhost-device-sound/src/audio_backends/pipewire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl AudioBackend for PwBackend {
.write()
.unwrap()
.get_mut(stream_id as usize)
.ok_or_else(|| Error::StreamWithIdNotFound(stream_id))?
.ok_or(Error::StreamWithIdNotFound(stream_id))?
.state
.prepare();
if let Err(err) = prepare_result {
Expand Down Expand Up @@ -500,7 +500,7 @@ impl AudioBackend for PwBackend {
.write()
.unwrap()
.get_mut(stream_id as usize)
.ok_or_else(|| Error::StreamWithIdNotFound(stream_id))?
.ok_or(Error::StreamWithIdNotFound(stream_id))?
.state
.release();
if let Err(err) = release_result {
Expand Down Expand Up @@ -529,7 +529,7 @@ impl AudioBackend for PwBackend {
.write()
.unwrap()
.get_mut(stream_id as usize)
.ok_or_else(|| Error::StreamWithIdNotFound(stream_id))?
.ok_or(Error::StreamWithIdNotFound(stream_id))?
.state
.start();
if let Err(err) = start_result {
Expand All @@ -554,7 +554,7 @@ impl AudioBackend for PwBackend {
.write()
.unwrap()
.get_mut(stream_id as usize)
.ok_or_else(|| Error::StreamWithIdNotFound(stream_id))?
.ok_or(Error::StreamWithIdNotFound(stream_id))?
.state
.stop();
if let Err(err) = stop_result {
Expand Down
4 changes: 2 additions & 2 deletions vhost-device-sound/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ impl VhostUserSoundThread {
) -> IoResult<()> {
let vring = &vrings
.get(device_event as usize)
.ok_or_else(|| Error::HandleUnknownEvent(device_event))?;
.ok_or(Error::HandleUnknownEvent(device_event))?;
let queue_idx = self
.queue_indexes
.get(device_event as usize)
.ok_or_else(|| Error::HandleUnknownEvent(device_event))?;
.ok_or(Error::HandleUnknownEvent(device_event))?;
if self.event_idx {
// vm-virtio's Queue implementation only checks avail_index
// once, so to properly support EVENT_IDX we need to keep
Expand Down
2 changes: 1 addition & 1 deletion vhost-device-sound/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl std::fmt::Debug for Request {
}

impl Request {
pub fn new(len: usize, message: Arc<IOMessage>, direction: Direction) -> Self {
pub const fn new(len: usize, message: Arc<IOMessage>, direction: Direction) -> Self {
Self {
pos: 0,
len,
Expand Down

0 comments on commit 4ea77f5

Please sign in to comment.