chore: fix clippy (#799)

This commit is contained in:
zach
2024-12-02 16:46:48 -08:00
committed by GitHub
parent 4f599d4b20
commit 5d18cc71eb
8 changed files with 29 additions and 29 deletions

View File

@@ -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<u8>;
fn to_bytes(&self) -> Result<Self::Bytes, Error> {
@@ -85,7 +85,7 @@ impl<T: AsRef<[u8]>> From<T> for Base64<T> {
}
}
impl<'a, T: AsRef<[u8]>> ToBytes<'a> for Base64<T> {
impl<T: AsRef<[u8]>> ToBytes<'_> for Base64<T> {
type Bytes = String;
fn to_bytes(&self) -> Result<Self::Bytes, Error> {
@@ -124,7 +124,7 @@ impl<T: prost::Message> From<T> for Prost<T> {
}
#[cfg(feature = "prost")]
impl<'a, T: prost::Message> ToBytes<'a> for Prost<T> {
impl<T: prost::Message> ToBytes<'_> for Prost<T> {
type Bytes = Vec<u8>;
fn to_bytes(&self) -> Result<Self::Bytes, Error> {
@@ -146,7 +146,7 @@ impl<T: Default + prost::Message> FromBytesOwned for Prost<T> {
pub struct Protobuf<T: protobuf::Message>(pub T);
#[cfg(feature = "protobuf")]
impl<'a, T: protobuf::Message> ToBytes<'a> for Protobuf<T> {
impl<T: protobuf::Message> ToBytes<'_> for Protobuf<T> {
type Bytes = Vec<u8>;
fn to_bytes(&self) -> Result<Self::Bytes, Error> {

View File

@@ -62,7 +62,7 @@ fn rountrip_option() {
}
#[cfg(all(feature = "raw", target_endian = "little"))]
mod tests {
mod raw_tests {
use crate::*;
#[test]

View File

@@ -61,21 +61,21 @@ pub trait ToBytes<'a> {
fn to_bytes(&self) -> Result<Self::Bytes, Error>;
}
impl<'a> ToBytes<'a> for () {
impl ToBytes<'_> for () {
type Bytes = [u8; 0];
fn to_bytes(&self) -> Result<Self::Bytes, Error> {
Ok([])
}
}
impl<'a> ToBytes<'a> for Vec<u8> {
impl ToBytes<'_> for Vec<u8> {
type Bytes = Vec<u8>;
fn to_bytes(&self) -> Result<Self::Bytes, Error> {
Ok(self.clone())
}
}
impl<'a> ToBytes<'a> for String {
impl ToBytes<'_> for String {
type Bytes = String;
fn to_bytes(&self) -> Result<Self::Bytes, Error> {
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<Self::Bytes, Error> {
@@ -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<Self::Bytes, Error> {
@@ -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<Self::Bytes, Error> {
@@ -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<Self::Bytes, Error> {
@@ -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<Self::Bytes, Error> {
@@ -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<Self::Bytes, Error> {

View File

@@ -269,8 +269,8 @@ pub struct Manifest {
/// Config values are made accessible using the PDK `extism_config_get` function
#[serde(default)]
pub config: BTreeMap<String, String>,
#[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<Vec<String>>,
@@ -417,14 +417,14 @@ mod wasmdata {
}
}
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)
}
}
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)

View File

@@ -199,7 +199,7 @@ pub enum WasmInput<'a> {
ManifestRef(&'a Manifest),
}
impl<'a> From<Manifest> for WasmInput<'a> {
impl From<Manifest> 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<Vec<u8>> for WasmInput<'a> {
impl From<Vec<u8>> for WasmInput<'_> {
fn from(value: Vec<u8>) -> 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<Self, Self::Error> {
fn try_from(x: $crate::Plugin) -> Result<Self, Self::Error> {
$(
if !x.function_exists(stringify!($f)) {
return Err($crate::Error::msg(format!("Invalid function: {}", stringify!($f))));

View File

@@ -884,7 +884,7 @@ fn set_log_file(log_file: impl Into<std::path::PathBuf>, filter: &str) -> Result
Ok(())
}
static mut LOG_BUFFER: Option<LogBuffer> = None;
static LOG_BUFFER: std::sync::Mutex<Option<LogBuffer>> = 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);

View File

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

View File

@@ -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<Option<Timer>> = std::sync::Mutex::new(None);
static TIMER: std::sync::Mutex<Option<Timer>> = std::sync::Mutex::new(None);
impl Timer {
pub(crate) fn tx() -> std::sync::mpsc::Sender<TimerAction> {
let mut timer = match unsafe { TIMER.lock() } {
let mut timer = match TIMER.lock() {
Ok(x) => x,
Err(e) => e.into_inner(),
};