From 5d18cc71eb8eebf94c7fd864a0f40970be63771f Mon Sep 17 00:00:00 2001 From: zach Date: Mon, 2 Dec 2024 16:46:48 -0800 Subject: [PATCH] chore: fix clippy (#799) --- convert/src/encoding.rs | 8 ++++---- convert/src/tests.rs | 2 +- convert/src/to_bytes.rs | 18 +++++++++--------- manifest/src/lib.rs | 6 +++--- runtime/src/plugin.rs | 6 +++--- runtime/src/sdk.rs | 8 ++++---- runtime/src/tests/runtime.rs | 4 ++-- runtime/src/timer.rs | 6 +++--- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/convert/src/encoding.rs b/convert/src/encoding.rs index 54a1e69..6b6dccf 100644 --- a/convert/src/encoding.rs +++ b/convert/src/encoding.rs @@ -55,7 +55,7 @@ encoding!(pub Json, serde_json::to_vec, serde_json::from_slice); #[cfg(feature = "msgpack")] encoding!(pub Msgpack, rmp_serde::to_vec, rmp_serde::from_slice); -impl<'a> ToBytes<'a> for serde_json::Value { +impl ToBytes<'_> for serde_json::Value { type Bytes = Vec; fn to_bytes(&self) -> Result { @@ -85,7 +85,7 @@ impl> From for Base64 { } } -impl<'a, T: AsRef<[u8]>> ToBytes<'a> for Base64 { +impl> ToBytes<'_> for Base64 { type Bytes = String; fn to_bytes(&self) -> Result { @@ -124,7 +124,7 @@ impl From for Prost { } #[cfg(feature = "prost")] -impl<'a, T: prost::Message> ToBytes<'a> for Prost { +impl ToBytes<'_> for Prost { type Bytes = Vec; fn to_bytes(&self) -> Result { @@ -146,7 +146,7 @@ impl FromBytesOwned for Prost { pub struct Protobuf(pub T); #[cfg(feature = "protobuf")] -impl<'a, T: protobuf::Message> ToBytes<'a> for Protobuf { +impl ToBytes<'_> for Protobuf { type Bytes = Vec; fn to_bytes(&self) -> Result { diff --git a/convert/src/tests.rs b/convert/src/tests.rs index 23261c5..5323166 100644 --- a/convert/src/tests.rs +++ b/convert/src/tests.rs @@ -62,7 +62,7 @@ fn rountrip_option() { } #[cfg(all(feature = "raw", target_endian = "little"))] -mod tests { +mod raw_tests { use crate::*; #[test] diff --git a/convert/src/to_bytes.rs b/convert/src/to_bytes.rs index fb40737..b49202f 100644 --- a/convert/src/to_bytes.rs +++ b/convert/src/to_bytes.rs @@ -61,21 +61,21 @@ pub trait ToBytes<'a> { fn to_bytes(&self) -> Result; } -impl<'a> ToBytes<'a> for () { +impl ToBytes<'_> for () { type Bytes = [u8; 0]; fn to_bytes(&self) -> Result { Ok([]) } } -impl<'a> ToBytes<'a> for Vec { +impl ToBytes<'_> for Vec { type Bytes = Vec; fn to_bytes(&self) -> Result { Ok(self.clone()) } } -impl<'a> ToBytes<'a> for String { +impl ToBytes<'_> for String { type Bytes = String; fn to_bytes(&self) -> Result { Ok(self.clone()) @@ -96,7 +96,7 @@ impl<'a> ToBytes<'a> for &'a str { } } -impl<'a> ToBytes<'a> for f64 { +impl ToBytes<'_> for f64 { type Bytes = [u8; 8]; fn to_bytes(&self) -> Result { @@ -104,7 +104,7 @@ impl<'a> ToBytes<'a> for f64 { } } -impl<'a> ToBytes<'a> for f32 { +impl ToBytes<'_> for f32 { type Bytes = [u8; 4]; fn to_bytes(&self) -> Result { @@ -112,7 +112,7 @@ impl<'a> ToBytes<'a> for f32 { } } -impl<'a> ToBytes<'a> for i64 { +impl ToBytes<'_> for i64 { type Bytes = [u8; 8]; fn to_bytes(&self) -> Result { @@ -120,7 +120,7 @@ impl<'a> ToBytes<'a> for i64 { } } -impl<'a> ToBytes<'a> for i32 { +impl ToBytes<'_> for i32 { type Bytes = [u8; 4]; fn to_bytes(&self) -> Result { @@ -128,7 +128,7 @@ impl<'a> ToBytes<'a> for i32 { } } -impl<'a> ToBytes<'a> for u64 { +impl ToBytes<'_> for u64 { type Bytes = [u8; 8]; fn to_bytes(&self) -> Result { @@ -136,7 +136,7 @@ impl<'a> ToBytes<'a> for u64 { } } -impl<'a> ToBytes<'a> for u32 { +impl ToBytes<'_> for u32 { type Bytes = [u8; 4]; fn to_bytes(&self) -> Result { diff --git a/manifest/src/lib.rs b/manifest/src/lib.rs index c1ab6b3..74e9f20 100644 --- a/manifest/src/lib.rs +++ b/manifest/src/lib.rs @@ -269,8 +269,8 @@ pub struct Manifest { /// Config values are made accessible using the PDK `extism_config_get` function #[serde(default)] pub config: BTreeMap, - #[serde(default)] + #[serde(default)] /// Specifies which hosts may be accessed via HTTP, if this is empty then /// no hosts may be accessed. Wildcards may be used. pub allowed_hosts: Option>, @@ -417,14 +417,14 @@ mod wasmdata { } } -impl<'a> From for std::borrow::Cow<'a, [u8]> { +impl From for std::borrow::Cow<'_, [u8]> { fn from(m: Manifest) -> Self { let s = serde_json::to_vec(&m).unwrap(); std::borrow::Cow::Owned(s) } } -impl<'a> From<&Manifest> for std::borrow::Cow<'a, [u8]> { +impl From<&Manifest> for std::borrow::Cow<'_, [u8]> { fn from(m: &Manifest) -> Self { let s = serde_json::to_vec(&m).unwrap(); std::borrow::Cow::Owned(s) diff --git a/runtime/src/plugin.rs b/runtime/src/plugin.rs index 2462ece..2d0204d 100644 --- a/runtime/src/plugin.rs +++ b/runtime/src/plugin.rs @@ -199,7 +199,7 @@ pub enum WasmInput<'a> { ManifestRef(&'a Manifest), } -impl<'a> From for WasmInput<'a> { +impl From for WasmInput<'_> { fn from(value: Manifest) -> Self { WasmInput::Manifest(value) } @@ -229,7 +229,7 @@ impl<'a> From<&'a str> for WasmInput<'a> { } } -impl<'a> From> for WasmInput<'a> { +impl From> for WasmInput<'_> { fn from(value: Vec) -> Self { WasmInput::Data(value.into()) } @@ -1168,7 +1168,7 @@ macro_rules! typed_plugin { impl TryFrom<$crate::Plugin> for $name { type Error = $crate::Error; - fn try_from(mut x: $crate::Plugin) -> Result { + fn try_from(x: $crate::Plugin) -> Result { $( if !x.function_exists(stringify!($f)) { return Err($crate::Error::msg(format!("Invalid function: {}", stringify!($f)))); diff --git a/runtime/src/sdk.rs b/runtime/src/sdk.rs index fde37cd..07a692e 100644 --- a/runtime/src/sdk.rs +++ b/runtime/src/sdk.rs @@ -884,7 +884,7 @@ fn set_log_file(log_file: impl Into, filter: &str) -> Result Ok(()) } -static mut LOG_BUFFER: Option = None; +static LOG_BUFFER: std::sync::Mutex> = std::sync::Mutex::new(None); /// Enable a custom log handler, this will buffer logs until `extism_log_drain` is called /// Log level should be one of: info, error, trace, debug, warn @@ -916,8 +916,8 @@ unsafe fn set_log_buffer(filter: &str) -> Result<(), Error> { x.parse_lossy(filter) } }); - LOG_BUFFER = Some(LogBuffer::default()); - let buf = LOG_BUFFER.clone().unwrap(); + *LOG_BUFFER.lock().unwrap() = Some(LogBuffer::default()); + let buf = LOG_BUFFER.lock().unwrap().clone().unwrap(); cfg.with_ansi(false) .with_writer(move || buf.clone()) .try_init() @@ -929,7 +929,7 @@ unsafe fn set_log_buffer(filter: &str) -> Result<(), Error> { /// Calls the provided callback function for each buffered log line. /// This is only needed when `extism_log_custom` is used. pub unsafe extern "C" fn extism_log_drain(handler: ExtismLogDrainFunctionType) { - if let Some(buf) = LOG_BUFFER.as_mut() { + if let Some(buf) = LOG_BUFFER.lock().unwrap().as_mut() { if let Ok(mut buf) = buf.buffer.lock() { for (line, len) in buf.drain(..) { handler(line.as_ptr(), len as u64); diff --git a/runtime/src/tests/runtime.rs b/runtime/src/tests/runtime.rs index b8fcece..b94fffa 100644 --- a/runtime/src/tests/runtime.rs +++ b/runtime/src/tests/runtime.rs @@ -447,7 +447,7 @@ fn hello_world_set_error( _user_data: UserData<()>, ) -> Result<(), Error> { plugin.set_error("TEST")?; - outputs[0] = inputs[0].clone(); + outputs[0] = inputs[0]; Ok(()) } @@ -544,7 +544,7 @@ fn hello_world_user_data( let mut data = data.lock().unwrap(); let s = _plugin.memory_get_val(&inputs[0])?; data.write_all(s)?; - outputs[0] = inputs[0].clone(); + outputs[0] = inputs[0]; Ok(()) } diff --git a/runtime/src/timer.rs b/runtime/src/timer.rs index de59adc..841b6a3 100644 --- a/runtime/src/timer.rs +++ b/runtime/src/timer.rs @@ -22,18 +22,18 @@ pub(crate) struct Timer { #[cfg(not(target_family = "windows"))] extern "C" fn cleanup_timer() { - let mut timer = match unsafe { TIMER.lock() } { + let mut timer = match TIMER.lock() { Ok(x) => x, Err(e) => e.into_inner(), }; drop(timer.take()); } -static mut TIMER: std::sync::Mutex> = std::sync::Mutex::new(None); +static TIMER: std::sync::Mutex> = std::sync::Mutex::new(None); impl Timer { pub(crate) fn tx() -> std::sync::mpsc::Sender { - let mut timer = match unsafe { TIMER.lock() } { + let mut timer = match TIMER.lock() { Ok(x) => x, Err(e) => e.into_inner(), };