difftreelog
style fix clippy warnings
in: master
3 files changed
bindings/jsonnet/src/native.rsdiffbeforeafterboth1use std::{2 borrow::Cow,3 ffi::{c_void, CStr},4 os::raw::{c_char, c_int},5};67use jrsonnet_evaluator::{8 error::{Error, ErrorKind},9 function::builtin::{NativeCallback, NativeCallbackHandler},10 typed::Typed,11 IStr, Val,12};1314use crate::VM;1516/// The returned `JsonnetJsonValue*` should be allocated with `jsonnet_realloc`. It will be cleaned up17/// along with the objects rooted at `argv` by `libjsonnet` when no-longer needed. Return a string upon18/// failure, which will appear in Jsonnet as an error. The `argv` pointer is an array whose size19/// matches the array of parameters supplied when the native callback was originally registered.20///21/// - `ctx` User pointer, given in jsonnet_native_callback.22/// - `argv` Array of arguments from Jsonnet code.23/// - `param` success Set this byref param to 1 to indicate success and 0 for failure.24/// Returns the content of the imported file, or an error message.25type JsonnetNativeCallback = unsafe extern "C" fn(26 ctx: *const c_void,27 argv: *const *const Val,28 success: *mut c_int,29) -> *mut Val;3031#[derive(jrsonnet_gcmodule::Trace)]32struct JsonnetNativeCallbackHandler {33 #[trace(skip)]34 ctx: *const c_void,35 #[trace(skip)]36 cb: JsonnetNativeCallback,37}38impl NativeCallbackHandler for JsonnetNativeCallbackHandler {39 fn call(&self, args: &[Val]) -> Result<Val, Error> {40 let mut n_args = Vec::new();41 for a in args {42 n_args.push(Some(Box::new(a.clone())));43 }44 n_args.push(None);45 let mut success = 1;46 let v = unsafe {47 (self.cb)(48 self.ctx,49 n_args.as_ptr().cast(),50 &mut success,51 )52 };53 let v = unsafe { *Box::from_raw(v) };54 if success == 1 {55 Ok(v)56 } else {57 let e = IStr::from_untyped(v).expect("error msg should be a string");58 Err(ErrorKind::RuntimeError(e).into())59 }60 }61}6263/// Callback to provide native extensions to Jsonnet.64///65/// # Safety66///67/// `vm` should be a vm allocated by `jsonnet_make`68/// `name` should be a NUL-terminated string69/// `cb` should be a function pointer70/// `raw_params` should point to a NULL-terminated array of NUL-terminated strings71#[no_mangle]72pub unsafe extern "C" fn jsonnet_native_callback(73 vm: &VM,74 name: *const c_char,75 cb: JsonnetNativeCallback,76 ctx: *const c_void,77 mut raw_params: *const *const c_char,78) {79 let name = CStr::from_ptr(name)80 .to_str()81 .expect("name is not utf-8")82 .into();83 let mut params = Vec::new();84 loop {85 if (*raw_params).is_null() {86 break;87 }88 let param = CStr::from_ptr(*raw_params)89 .to_str()90 .expect("param name is not utf-8");91 params.push(Cow::Owned(param.into()));92 raw_params = raw_params.offset(1);93 }9495 let any_resolver = vm.state.context_initializer();96 any_resolver97 .as_any()98 .downcast_ref::<jrsonnet_stdlib::ContextInitializer>()99 .expect("only stdlib context initializer supported")100 .add_native(101 name,102 #[allow(deprecated)]103 NativeCallback::new(params, JsonnetNativeCallbackHandler { ctx, cb }),104 )105}1use std::{2 borrow::Cow,3 ffi::{c_void, CStr},4 os::raw::{c_char, c_int},5};67use jrsonnet_evaluator::{8 error::{Error, ErrorKind},9 function::builtin::{NativeCallback, NativeCallbackHandler},10 typed::Typed,11 IStr, Val,12};1314use crate::VM;1516/// The returned `JsonnetJsonValue*` should be allocated with `jsonnet_realloc`. It will be cleaned up17/// along with the objects rooted at `argv` by `libjsonnet` when no-longer needed. Return a string upon18/// failure, which will appear in Jsonnet as an error. The `argv` pointer is an array whose size19/// matches the array of parameters supplied when the native callback was originally registered.20///21/// - `ctx` User pointer, given in jsonnet_native_callback.22/// - `argv` Array of arguments from Jsonnet code.23/// - `param` success Set this byref param to 1 to indicate success and 0 for failure.24/// Returns the content of the imported file, or an error message.25type JsonnetNativeCallback = unsafe extern "C" fn(26 ctx: *const c_void,27 argv: *const *const Val,28 success: *mut c_int,29) -> *mut Val;3031#[derive(jrsonnet_gcmodule::Trace)]32struct JsonnetNativeCallbackHandler {33 #[trace(skip)]34 ctx: *const c_void,35 #[trace(skip)]36 cb: JsonnetNativeCallback,37}38impl NativeCallbackHandler for JsonnetNativeCallbackHandler {39 fn call(&self, args: &[Val]) -> Result<Val, Error> {40 let mut n_args = Vec::new();41 for a in args {42 n_args.push(Some(Box::new(a.clone())));43 }44 n_args.push(None);45 let mut success = 1;46 let v = unsafe { (self.cb)(self.ctx, n_args.as_ptr().cast(), &mut success) };47 let v = unsafe { *Box::from_raw(v) };48 if success == 1 {49 Ok(v)50 } else {51 let e = IStr::from_untyped(v).expect("error msg should be a string");52 Err(ErrorKind::RuntimeError(e).into())53 }54 }55}5657/// Callback to provide native extensions to Jsonnet.58///59/// # Safety60///61/// `vm` should be a vm allocated by `jsonnet_make`62/// `name` should be a NUL-terminated string63/// `cb` should be a function pointer64/// `raw_params` should point to a NULL-terminated array of NUL-terminated strings65#[no_mangle]66pub unsafe extern "C" fn jsonnet_native_callback(67 vm: &VM,68 name: *const c_char,69 cb: JsonnetNativeCallback,70 ctx: *const c_void,71 mut raw_params: *const *const c_char,72) {73 let name = CStr::from_ptr(name)74 .to_str()75 .expect("name is not utf-8")76 .into();77 let mut params = Vec::new();78 loop {79 if (*raw_params).is_null() {80 break;81 }82 let param = CStr::from_ptr(*raw_params)83 .to_str()84 .expect("param name is not utf-8");85 params.push(Cow::Owned(param.into()));86 raw_params = raw_params.offset(1);87 }8889 let any_resolver = vm.state.context_initializer();90 any_resolver91 .as_any()92 .downcast_ref::<jrsonnet_stdlib::ContextInitializer>()93 .expect("only stdlib context initializer supported")94 .add_native(95 name,96 #[allow(deprecated)]97 NativeCallback::new(params, JsonnetNativeCallbackHandler { ctx, cb }),98 )99}crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -28,26 +28,26 @@
use jrsonnet_gcmodule::Trace;
#[derive(Clone, Copy, Default, Debug, Trace)]
- pub struct FieldIndex;
+ pub struct FieldIndex(());
impl FieldIndex {
pub const fn next(self) -> Self {
- Self
+ Self(())
}
}
#[derive(Clone, Copy, Default, Debug, Trace)]
- pub struct SuperDepth;
+ pub struct SuperDepth(());
impl SuperDepth {
pub const fn deeper(self) -> Self {
- Self
+ Self(())
}
}
#[derive(Clone, Copy)]
- pub struct FieldSortKey;
+ pub struct FieldSortKey(());
impl FieldSortKey {
pub const fn new(_: SuperDepth, _: FieldIndex) -> Self {
- Self
+ Self(())
}
}
}
crates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-interner/src/lib.rs
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -79,7 +79,7 @@
impl Drop for IStr {
fn drop(&mut self) {
- maybe_unpool(&self.0)
+ maybe_unpool(&self.0);
}
}
@@ -151,7 +151,7 @@
impl Drop for IBytes {
fn drop(&mut self) {
- maybe_unpool(&self.0)
+ maybe_unpool(&self.0);
}
}
@@ -176,8 +176,8 @@
});
}
// First reference - current object, second - POOL
- if Inner::strong_count(&inner) <= 2 {
- unpool(&inner);
+ if Inner::strong_count(inner) <= 2 {
+ unpool(inner);
}
}