git.delta.rocks / jrsonnet / refs/commits / 097494ede5f1

difftreelog

refactor trivial code review suggestions

Yaroslav Bolyukin2022-09-18parent: #f2fefaf.patch.diff
in: master

8 files changed

modifiedbindings/jsonnet/src/lib.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -25,9 +25,10 @@
 #[no_mangle]
 pub extern "C" fn _start() {}
 
-/// Return the version string of the Jsonnet interpreter.  Conforms to semantic versioning
-/// http://semver.org/ If this does not match LIB_JSONNET_VERSION then there is a mismatch between
-/// header and compiled library.
+/// Return the version string of the Jsonnet interpreter.
+/// Conforms to [semantic versioning](http://semver.org/).
+/// If this does not match `LIB_JSONNET_VERSION`
+/// then there is a mismatch between header and compiled library.
 #[no_mangle]
 pub extern "C" fn jsonnet_version() -> &'static [u8; 8] {
 	b"v0.16.0\0"
@@ -67,7 +68,7 @@
 	}
 }
 
-/// Create a new Jsonnet virtual machine.
+/// Creates a new Jsonnet virtual machine.
 #[no_mangle]
 pub extern "C" fn jsonnet_make() -> *mut State {
 	let state = State::default();
@@ -79,7 +80,7 @@
 	Box::into_raw(Box::new(state))
 }
 
-/// Complement of `jsonnet_vm_make`
+/// Complement of [`jsonnet_vm_make`].
 #[no_mangle]
 #[allow(clippy::boxed_local)]
 pub extern "C" fn jsonnet_destroy(vm: Box<State>) {
@@ -118,7 +119,7 @@
 	}
 }
 
-/// Allocate, resize, or free a buffer.  This will abort if the memory cannot be allocated.  It will
+/// Allocate, resize, or free a buffer.  This will abort if the memory cannot be allocated. It will
 /// only return NULL if sz was zero.
 ///
 /// # Safety
modifiedbindings/jsonnet/src/native.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/native.rs
+++ b/bindings/jsonnet/src/native.rs
@@ -12,9 +12,9 @@
 };
 use jrsonnet_gcmodule::Cc;
 
-/// The returned JsonnetJsonValue* should be allocated with jsonnet_realloc.  It will be cleaned up
-/// along with the objects rooted at argv by libjsonnet when no-longer needed.  Return a string upon
-/// failure, which will appear in Jsonnet as an error.  The argv pointer is an array whose size
+/// The returned `JsonnetJsonValue*` should be allocated with `jsonnet_realloc`. It will be cleaned up
+/// along with the objects rooted at `argv` by `libjsonnet` when no-longer needed. Return a string upon
+/// failure, which will appear in Jsonnet as an error. The `argv` pointer is an array whose size
 /// matches the array of parameters supplied when the native callback was originally registered.
 ///
 /// - `ctx` User pointer, given in jsonnet_native_callback.
modifiedbindings/jsonnet/src/val_extract.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_extract.rs
+++ b/bindings/jsonnet/src/val_extract.rs
@@ -7,7 +7,7 @@
 
 use jrsonnet_evaluator::{State, Val};
 
-/// If the value is a string, return it as UTF8 otherwise return NULL.
+/// If the value is a string, return it as UTF-8, otherwise return `NULL`.
 #[no_mangle]
 pub extern "C" fn jsonnet_json_extract_string(_vm: &State, v: &Val) -> *mut c_char {
 	match v {
@@ -16,7 +16,7 @@
 	}
 }
 
-/// If the value is a number, return 1 and store the number in out, otherwise return 0.
+/// If the value is a number, return `1` and store the number in out, otherwise return `0`.
 #[no_mangle]
 pub extern "C" fn jsonnet_json_extract_number(_vm: &State, v: &Val, out: &mut c_double) -> c_int {
 	match v {
@@ -28,7 +28,7 @@
 	}
 }
 
-/// Return 0 if the value is false, 1 if it is true, and 2 if it is not a bool.
+/// Return `0` if the value is `false`, `1` if it is `true`, and `2` if it is not a `bool`.
 #[no_mangle]
 pub extern "C" fn jsonnet_json_extract_bool(_vm: &State, v: &Val) -> c_int {
 	match v {
@@ -38,7 +38,7 @@
 	}
 }
 
-/// Return 1 if the value is null, else 0.
+/// Return `1` if the value is `null`, otherwise return `0`.
 #[no_mangle]
 pub extern "C" fn jsonnet_json_extract_null(_vm: &State, v: &Val) -> c_int {
 	match v {
modifiedbindings/jsonnet/src/val_make.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_make.rs
+++ b/bindings/jsonnet/src/val_make.rs
@@ -8,7 +8,7 @@
 use jrsonnet_evaluator::{val::ArrValue, ObjValue, State, Val};
 use jrsonnet_gcmodule::Cc;
 
-/// Convert the given UTF8 string to a JsonnetJsonValue.
+/// Convert the given `UTF-8` string to a `JsonnetJsonValue`.
 ///
 /// # Safety
 ///
@@ -20,34 +20,34 @@
 	Box::into_raw(Box::new(Val::Str(val.into())))
 }
 
-/// Convert the given double to a JsonnetJsonValue.
+/// Convert the given double to a `JsonnetJsonValue`.
 #[no_mangle]
 pub extern "C" fn jsonnet_json_make_number(_vm: &State, v: c_double) -> *mut Val {
 	Box::into_raw(Box::new(Val::Num(v)))
 }
 
-/// Convert the given bool (1 or 0) to a JsonnetJsonValue.
+/// Convert the given `bool` (`1` or `0`) to a `JsonnetJsonValue`.
 #[no_mangle]
 pub extern "C" fn jsonnet_json_make_bool(_vm: &State, v: c_int) -> *mut Val {
 	assert!(v == 0 || v == 1, "bad boolean value");
 	Box::into_raw(Box::new(Val::Bool(v == 1)))
 }
 
-/// Make a JsonnetJsonValue representing null.
+/// Make a `JsonnetJsonValue` representing `null`.
 #[no_mangle]
 pub extern "C" fn jsonnet_json_make_null(_vm: &State) -> *mut Val {
 	Box::into_raw(Box::new(Val::Null))
 }
 
-/// Make a JsonnetJsonValue representing an array.
+/// Make a `JsonnetJsonValue` representing an array.
 ///
-/// Assign elements with jsonnet_json_array_append.
+/// Assign elements with [`jsonnet_json_array_append`].
 #[no_mangle]
 pub extern "C" fn jsonnet_json_make_array(_vm: &State) -> *mut Val {
 	Box::into_raw(Box::new(Val::Arr(ArrValue::Eager(Cc::new(Vec::new())))))
 }
 
-/// Make a JsonnetJsonValue representing an object.
+/// Make a `JsonnetJsonValue` representing an object.
 #[no_mangle]
 pub extern "C" fn jsonnet_json_make_object(_vm: &State) -> *mut Val {
 	Box::into_raw(Box::new(Val::Obj(ObjValue::new_empty())))
modifiedbindings/jsonnet/src/val_modify.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_modify.rs
+++ b/bindings/jsonnet/src/val_modify.rs
@@ -7,7 +7,7 @@
 use jrsonnet_evaluator::{val::ArrValue, State, Thunk, Val};
 use jrsonnet_gcmodule::Cc;
 
-/// Add value to the end of the array arr
+/// Adds value to the end of the array `arr`.
 ///
 /// # Safety
 ///
@@ -29,13 +29,13 @@
 	}
 }
 
-/// Add the field to the object, bound to value.
+/// Adds the field to the object, bound to value.
 ///
 /// This shadows any previous binding of the field.
 ///
 /// # Safety
 ///
-/// `obj` should be pointer to object value allocated by make_object, or returned by other library call
+/// `obj` should be a valid pointer to object value allocated by `make_object`, or returned by other library call
 /// `name` should be \0-terminated string
 #[no_mangle]
 pub unsafe extern "C" fn jsonnet_json_object_append(
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
105 fn as_any(&self) -> &dyn Any;105 fn as_any(&self) -> &dyn Any;
106}106}
107107
108/// Context initializer, which adds noth108/// Context initializer which adds nothing.
109pub struct DummyContextInitializer;109pub struct DummyContextInitializer;
110impl ContextInitializer for DummyContextInitializer {110impl ContextInitializer for DummyContextInitializer {
111 fn initialize(&self, _state: State, _for_file: Source) -> Context {111 fn initialize(&self, _state: State, _for_file: Source) -> Context {
modifiedcrates/jrsonnet-stdlib/src/math.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/math.rs
+++ b/crates/jrsonnet-stdlib/src/math.rs
@@ -66,7 +66,7 @@
 }
 
 fn frexp(s: f64) -> (f64, i16) {
-	if 0.0 == s {
+	if s == 0.0 {
 		(s, 0)
 	} else {
 		let lg = s.abs().log2();
modifiedcrates/jrsonnet-stdlib/src/sort.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/sort.rs
+++ b/crates/jrsonnet-stdlib/src/sort.rs
@@ -41,9 +41,9 @@
 			(Val::Num(_), SortKeyType::Unknown) => sort_type = SortKeyType::Number,
 			(Val::Str(_), SortKeyType::String) | (Val::Num(_), SortKeyType::Number) => {}
 			(Val::Str(_) | Val::Num(_), _) => {
-				throw_runtime!("sort elements should have same types")
+				throw_runtime!("sort elements should have the same types")
 			}
-			_ => throw_runtime!("sort key should be string or number"),
+			_ => throw_runtime!("sort key should either be a string or a number"),
 		}
 	}
 	Ok(sort_type)