diff --git a/src/api/build_type.rs b/src/api/build_type.rs
index ae83def26..5b5e77a66 100644
--- a/src/api/build_type.rs
+++ b/src/api/build_type.rs
@@ -98,7 +98,6 @@ impl Engine {
///
/// To define a pretty-print name, call [`with_name`][`TypeBuilder::with_name`],
/// to use [`Engine::register_type_with_name`] instead.
-#[must_use]
pub struct TypeBuilder<'a, T: Variant + Clone> {
engine: &'a mut Engine,
name: Option<&'static str>,
diff --git a/src/api/call_fn.rs b/src/api/call_fn.rs
index 3206755d3..bba9a2586 100644
--- a/src/api/call_fn.rs
+++ b/src/api/call_fn.rs
@@ -14,7 +14,6 @@ use std::{any::type_name, mem};
/// Options for calling a script-defined function via [`Engine::call_fn_with_options`].
#[derive(Debug, Hash)]
#[non_exhaustive]
-#[must_use]
pub struct CallFnOptions<'t> {
/// A value for binding to the `this` pointer (if any). Default [`None`].
pub this_ptr: Option<&'t mut Dynamic>,
@@ -36,6 +35,7 @@ impl Default for CallFnOptions<'_> {
impl<'a> CallFnOptions<'a> {
/// Create a default [`CallFnOptions`].
#[inline(always)]
+ #[must_use]
pub fn new() -> Self {
Self {
this_ptr: None,
@@ -46,24 +46,28 @@ impl<'a> CallFnOptions<'a> {
}
/// Bind to the `this` pointer.
#[inline(always)]
+ #[must_use]
pub fn bind_this_ptr(mut self, value: &'a mut Dynamic) -> Self {
self.this_ptr = Some(value);
self
}
/// Set the custom state of this evaluation run (if any).
#[inline(always)]
+ #[must_use]
pub fn with_tag(mut self, value: impl Variant + Clone) -> Self {
self.tag = Some(Dynamic::from(value));
self
}
/// Set whether to evaluate the [`AST`] to load necessary modules before calling the function.
#[inline(always)]
+ #[must_use]
pub const fn eval_ast(mut self, value: bool) -> Self {
self.eval_ast = value;
self
}
/// Set whether to rewind the [`Scope`] after the function call.
#[inline(always)]
+ #[must_use]
pub const fn rewind_scope(mut self, value: bool) -> Self {
self.rewind_scope = value;
self
diff --git a/src/ast/script_fn.rs b/src/ast/script_fn.rs
index 5be3ba1d2..a566871a2 100644
--- a/src/ast/script_fn.rs
+++ b/src/ast/script_fn.rs
@@ -75,17 +75,30 @@ impl fmt::Display for ScriptFnDef {
///
/// Created by [`AST::iter_functions`][super::AST::iter_functions].
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Hash)]
+#[cfg_attr(
+ feature = "serde",
+ derive(serde::Serialize, serde::Deserialize),
+ serde(rename_all = "camelCase")
+)]
#[non_exhaustive]
pub struct ScriptFnMetadata<'a> {
/// Function name.
pub name: &'a str,
/// Function parameters (if any).
+ #[cfg_attr(
+ feature = "serde",
+ serde(default, skip_serializing_if = "Vec::is_empty")
+ )]
pub params: Vec<&'a str>,
/// Function access mode.
pub access: FnAccess,
- #[cfg(not(feature = "no_object"))]
/// Type of `this` pointer, if any.
/// Not available under `no_object`.
+ #[cfg(not(feature = "no_object"))]
+ #[cfg_attr(
+ feature = "serde",
+ serde(default, skip_serializing_if = "Option::is_none")
+ )]
pub this_type: Option<&'a str>,
/// _(metadata)_ Function doc-comments (if any).
/// Exported under the `metadata` feature only.
@@ -102,6 +115,10 @@ pub struct ScriptFnMetadata<'a> {
///
/// Each line in non-block doc-comments starts with `///`.
#[cfg(feature = "metadata")]
+ #[cfg_attr(
+ feature = "serde",
+ serde(default, skip_serializing_if = "Vec::is_empty")
+ )]
pub comments: Vec<&'a str>,
}
diff --git a/src/eval/chaining.rs b/src/eval/chaining.rs
index 8c0fd67de..66b7ea73e 100644
--- a/src/eval/chaining.rs
+++ b/src/eval/chaining.rs
@@ -21,6 +21,7 @@ static INDEXER_HASHES: OnceCell<(u64, u64)> = OnceCell::new();
#[must_use]
fn hash_idx() -> (u64, u64) {
*INDEXER_HASHES.get_or_init(|| {
+ #[allow(clippy::useless_conversion)]
(
calc_fn_hash(None, FN_IDX_GET, 2),
calc_fn_hash(None, FN_IDX_SET, 3),
diff --git a/src/lib.rs b/src/lib.rs
index 2eb92d205..88187e57e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -54,7 +54,9 @@
//!
//! # Features
//!
-#![cfg_attr(feature = "document-features", doc = document_features::document_features!(feature_label = "**`{feature}`**"))]
+#![cfg_attr(feature = "document-features", doc = document_features::document_features!(
+ feature_label = "**`{feature}`**"
+))]
//!
//! # On-Line Documentation
//!
diff --git a/src/serde/metadata.rs b/src/serde/metadata.rs
index bbc16d272..8d8bfb0a4 100644
--- a/src/serde/metadata.rs
+++ b/src/serde/metadata.rs
@@ -20,9 +20,9 @@ enum FnType {
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct FnParam<'a> {
- #[serde(skip_serializing_if = "Option::is_none")]
+ #[serde(default, skip_serializing_if = "Option::is_none")]
pub name: Option<&'a str>,
- #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
+ #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
pub typ: Option>,
}
@@ -164,14 +164,14 @@ impl<'a> From<&'a FuncInfo> for FnMetadata<'a> {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct ModuleMetadata<'a> {
- #[serde(skip_serializing_if = "str::is_empty")]
- pub doc: &'a str,
- #[serde(skip_serializing_if = "BTreeMap::is_empty")]
+ #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub modules: BTreeMap<&'a str, Self>,
- #[serde(skip_serializing_if = "Vec::is_empty")]
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
pub custom_types: Vec>,
- #[serde(skip_serializing_if = "Vec::is_empty")]
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
pub functions: Vec>,
+ #[serde(default, skip_serializing_if = "str::is_empty")]
+ pub doc: &'a str,
}
impl ModuleMetadata<'_> {
diff --git a/src/serde/ser.rs b/src/serde/ser.rs
index c4030dbde..d76975368 100644
--- a/src/serde/ser.rs
+++ b/src/serde/ser.rs
@@ -15,9 +15,9 @@ use num_traits::FromPrimitive;
/// Serializer for [`Dynamic`][crate::Dynamic].
pub struct DynamicSerializer {
/// Buffer to hold a temporary key.
- _key: Identifier,
+ key: Identifier,
/// Buffer to hold a temporary value.
- _value: Dynamic,
+ value: Dynamic,
}
impl DynamicSerializer {
@@ -25,8 +25,8 @@ impl DynamicSerializer {
#[must_use]
pub const fn new(value: Dynamic) -> Self {
Self {
- _key: Identifier::new_const(),
- _value: value,
+ key: Identifier::new_const(),
+ value,
}
}
}
@@ -464,7 +464,7 @@ impl SerializeSeq for DynamicSerializer {
#[cfg(not(feature = "no_index"))]
{
let value = _value.serialize(&mut *self)?;
- let arr = self._value.downcast_mut::().unwrap();
+ let arr = self.value.downcast_mut::().unwrap();
arr.push(value);
Ok(())
}
@@ -481,7 +481,7 @@ impl SerializeSeq for DynamicSerializer {
#[inline]
fn end(self) -> RhaiResultOf {
#[cfg(not(feature = "no_index"))]
- return Ok(self._value);
+ return Ok(self.value);
#[cfg(feature = "no_index")]
return Err(ERR::ErrorMismatchDataType(
"".into(),
@@ -500,7 +500,7 @@ impl SerializeTuple for DynamicSerializer {
#[cfg(not(feature = "no_index"))]
{
let value = _value.serialize(&mut *self)?;
- let arr = self._value.downcast_mut::().unwrap();
+ let arr = self.value.downcast_mut::().unwrap();
arr.push(value);
Ok(())
}
@@ -516,7 +516,7 @@ impl SerializeTuple for DynamicSerializer {
#[inline]
fn end(self) -> RhaiResultOf {
#[cfg(not(feature = "no_index"))]
- return Ok(self._value);
+ return Ok(self.value);
#[cfg(feature = "no_index")]
return Err(ERR::ErrorMismatchDataType(
"".into(),
@@ -535,7 +535,7 @@ impl SerializeTupleStruct for DynamicSerializer {
#[cfg(not(feature = "no_index"))]
{
let value = _value.serialize(&mut *self)?;
- let arr = self._value.downcast_mut::().unwrap();
+ let arr = self.value.downcast_mut::().unwrap();
arr.push(value);
Ok(())
}
@@ -551,7 +551,7 @@ impl SerializeTupleStruct for DynamicSerializer {
#[inline]
fn end(self) -> RhaiResultOf {
#[cfg(not(feature = "no_index"))]
- return Ok(self._value);
+ return Ok(self.value);
#[cfg(feature = "no_index")]
return Err(ERR::ErrorMismatchDataType(
"".into(),
@@ -570,7 +570,7 @@ impl SerializeMap for DynamicSerializer {
#[cfg(not(feature = "no_object"))]
{
let key = _key.serialize(&mut *self)?;
- self._key = key
+ self.key = key
.into_immutable_string()
.map_err(|typ| {
ERR::ErrorMismatchDataType("string".into(), typ.into(), Position::NONE)
@@ -590,9 +590,9 @@ impl SerializeMap for DynamicSerializer {
fn serialize_value(&mut self, _value: &T) -> RhaiResultOf<()> {
#[cfg(not(feature = "no_object"))]
{
- let key = std::mem::take(&mut self._key);
+ let key = std::mem::take(&mut self.key);
let value = _value.serialize(&mut *self)?;
- let map = self._value.downcast_mut::().unwrap();
+ let map = self.value.downcast_mut::().unwrap();
map.insert(key, value);
Ok(())
}
@@ -617,7 +617,7 @@ impl SerializeMap for DynamicSerializer {
ERR::ErrorMismatchDataType("string".into(), typ.into(), Position::NONE)
})?;
let value = _value.serialize(&mut *self)?;
- let map = self._value.downcast_mut::().unwrap();
+ let map = self.value.downcast_mut::().unwrap();
map.insert(key.into(), value);
Ok(())
}
@@ -633,7 +633,7 @@ impl SerializeMap for DynamicSerializer {
#[inline]
fn end(self) -> RhaiResultOf {
#[cfg(not(feature = "no_object"))]
- return Ok(self._value);
+ return Ok(self.value);
#[cfg(feature = "no_object")]
return Err(ERR::ErrorMismatchDataType(
"".into(),
@@ -656,7 +656,7 @@ impl SerializeStruct for DynamicSerializer {
#[cfg(not(feature = "no_object"))]
{
let value = _value.serialize(&mut *self)?;
- let map = self._value.downcast_mut::().unwrap();
+ let map = self.value.downcast_mut::().unwrap();
map.insert(_key.into(), value);
Ok(())
}
@@ -672,7 +672,7 @@ impl SerializeStruct for DynamicSerializer {
#[inline]
fn end(self) -> RhaiResultOf {
#[cfg(not(feature = "no_object"))]
- return Ok(self._value);
+ return Ok(self.value);
#[cfg(feature = "no_object")]
return Err(ERR::ErrorMismatchDataType(
"".into(),
diff --git a/src/types/custom_types.rs b/src/types/custom_types.rs
index 559be5e2b..3419fbb39 100644
--- a/src/types/custom_types.rs
+++ b/src/types/custom_types.rs
@@ -7,7 +7,8 @@ use std::{any::type_name, collections::BTreeMap};
/// _(internals)_ Information for a registered custom type.
/// Exported under the `internals` feature only.
-#[derive(Debug, Eq, PartialEq, Clone, Hash, Default)]
+#[derive(Debug, Eq, PartialEq, Clone, Hash)]
+#[non_exhaustive]
pub struct CustomTypeInfo {
/// Rust name of the custom type.
pub type_name: Identifier,
diff --git a/src/types/var_def.rs b/src/types/var_def.rs
index c46953c2a..2c83bc715 100644
--- a/src/types/var_def.rs
+++ b/src/types/var_def.rs
@@ -4,7 +4,7 @@
use std::prelude::v1::*;
/// Information on a variable definition.
-#[derive(Debug, Hash)]
+#[derive(Debug, Clone, Hash)]
pub struct VarDefInfo<'a> {
/// Name of the variable to be defined.
name: &'a str,