Add #[must_use]

This commit is contained in:
Stephen Chung
2021-06-12 22:47:43 +08:00
parent 68ea8c27fd
commit 8ca24059b1
28 changed files with 489 additions and 55 deletions

View File

@@ -28,14 +28,17 @@ impl<'de> DynamicDeserializer<'de> {
///
/// The reference is necessary because the deserialized type may hold references
/// (especially `&str`) to the source [`Dynamic`][crate::Dynamic].
#[must_use]
pub fn from_dynamic(value: &'de Dynamic) -> Self {
Self { value }
}
/// Shortcut for a type conversion error.
#[must_use]
fn type_error<T>(&self) -> Result<T, Box<EvalAltResult>> {
self.type_error_str(type_name::<T>())
}
/// Shortcut for a type conversion error.
#[must_use]
fn type_error_str<T>(&self, error: &str) -> Result<T, Box<EvalAltResult>> {
EvalAltResult::ErrorMismatchOutputType(
error.into(),
@@ -44,6 +47,7 @@ impl<'de> DynamicDeserializer<'de> {
)
.into()
}
#[must_use]
fn deserialize_int<V: Visitor<'de>>(
&mut self,
v: crate::INT,
@@ -107,6 +111,7 @@ impl<'de> DynamicDeserializer<'de> {
/// # Ok(())
/// # }
/// ```
#[must_use]
pub fn from_dynamic<'de, T: Deserialize<'de>>(
value: &'de Dynamic,
) -> Result<T, Box<EvalAltResult>> {
@@ -494,6 +499,7 @@ struct IterateArray<'a, ITER: Iterator<Item = &'a Dynamic>> {
#[cfg(not(feature = "no_index"))]
impl<'a, ITER: Iterator<Item = &'a Dynamic>> IterateArray<'a, ITER> {
#[must_use]
pub fn new(iter: ITER) -> Self {
Self { iter }
}
@@ -534,6 +540,7 @@ where
KEYS: Iterator<Item = &'a str>,
VALUES: Iterator<Item = &'a Dynamic>,
{
#[must_use]
pub fn new(keys: KEYS, values: VALUES) -> Self {
Self { keys, values }
}

View File

@@ -214,6 +214,7 @@ impl Engine {
/// 2) Functions registered into the global namespace
/// 3) Functions in static modules
/// 4) Functions in global modules (optional)
#[must_use]
pub fn gen_fn_metadata_with_ast_to_json(
&self,
ast: &AST,
@@ -253,6 +254,7 @@ impl Engine {
/// 1) Functions registered into the global namespace
/// 2) Functions in static modules
/// 3) Functions in global modules (optional)
#[must_use]
pub fn gen_fn_metadata_to_json(&self, include_global: bool) -> serde_json::Result<String> {
self.gen_fn_metadata_with_ast_to_json(&Default::default(), include_global)
}

View File

@@ -25,6 +25,7 @@ struct DynamicSerializer {
impl DynamicSerializer {
/// Create a [`DynamicSerializer`] from a [`Dynamic`][crate::Dynamic] value.
#[must_use]
pub fn new(_value: Dynamic) -> Self {
Self {
_key: Default::default(),
@@ -81,6 +82,7 @@ impl DynamicSerializer {
/// # Ok(())
/// # }
/// ```
#[must_use]
pub fn to_dynamic<T: Serialize>(value: T) -> RhaiResult {
let mut s = DynamicSerializer::new(Default::default());
value.serialize(&mut s)

View File

@@ -13,10 +13,12 @@ pub struct StringSliceDeserializer<'a> {
impl<'a> StringSliceDeserializer<'a> {
/// Create an `ImmutableStringDeserializer` from an `&str` reference.
#[must_use]
pub fn from_str(value: &'a str) -> Self {
Self { value }
}
/// Shortcut for a type conversion error.
#[must_use]
fn type_error<T>(&self) -> Result<T, Box<EvalAltResult>> {
EvalAltResult::ErrorMismatchOutputType(
type_name::<T>().into(),