sound: fix some minor clippy lints

Unnecessary lazy evaluation in Option::ok_or_else uses, constify some
functions.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
This commit is contained in:
Manos Pitsidianakis 2024-12-02 12:40:13 +02:00 committed by Stefano Garzarella
parent 937d28daee
commit 9757042216
5 changed files with 9 additions and 9 deletions

View File

@ -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()
{

View File

@ -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 }
}
}

View File

@ -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 {
@ -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 {
@ -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 {
@ -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 {

View File

@ -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

View File

@ -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,