From 6b5a14ee882fdec71034920825f34727469e6176 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 18 Jan 2021 10:23:41 +0800 Subject: [PATCH] Fix compilation bug. --- src/serde_impl/metadata.rs | 67 +++++++++++++++----------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/src/serde_impl/metadata.rs b/src/serde_impl/metadata.rs index 80a6cd01..85a63d87 100644 --- a/src/serde_impl/metadata.rs +++ b/src/serde_impl/metadata.rs @@ -2,7 +2,6 @@ use crate::stdlib::{ cmp::Ordering, collections::BTreeMap, string::{String, ToString}, - vec, vec::Vec, }; use crate::{Engine, AST}; @@ -89,7 +88,7 @@ struct FnMetadata { #[serde(default, skip_serializing_if = "Option::is_none")] pub return_type: Option, pub signature: String, - #[serde(default, skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub doc_comments: Vec, } @@ -125,31 +124,25 @@ impl From<&crate::module::FuncInfo> for FnMetadata { FnType::Native }, num_params: info.params, - params: if let Some(ref names) = info.param_names { - names - .iter() - .take(info.params) - .map(|s| { - let mut seg = s.splitn(2, ':'); - let name = seg - .next() - .map(|s| s.trim().to_string()) - .unwrap_or("_".to_string()); - let typ = seg.next().map(|s| s.trim().to_string()); - FnParam { name, typ } - }) - .collect() - } else { - vec![] - }, - return_type: if let Some(ref names) = info.param_names { - names - .last() - .map(|s| s.to_string()) - .or_else(|| Some("()".to_string())) - } else { - None - }, + params: info + .param_names + .iter() + .take(info.params) + .map(|s| { + let mut seg = s.splitn(2, ':'); + let name = seg + .next() + .map(|s| s.trim().to_string()) + .unwrap_or("_".to_string()); + let typ = seg.next().map(|s| s.trim().to_string()); + FnParam { name, typ } + }) + .collect(), + return_type: info + .param_names + .last() + .map(|s| s.to_string()) + .or_else(|| Some("()".to_string())), signature: info.gen_signature(), doc_comments: if info.func.is_script() { info.func.get_fn_def().comments.clone() @@ -178,11 +171,7 @@ impl From> for FnMetadata { .collect(), return_type: Some("Dynamic".to_string()), signature: info.to_string(), - doc_comments: if info.comments.is_empty() { - None - } else { - Some(info.comments.iter().map(|s| s.to_string()).collect()) - }, + doc_comments: info.comments.iter().map(|s| s.to_string()).collect(), } } } @@ -211,10 +200,10 @@ impl From<&crate::Module> for ModuleMetadata { } } -#[cfg(feature = "serde")] +#[cfg(feature = "metadata")] impl Engine { - /// Generate a list of all functions (including those defined in an [`AST`][crate::AST]) - /// in JSON format. Available only under the `metadata` feature. + /// _(METADATA)_ Generate a list of all functions (including those defined in an + /// [`AST`][crate::AST]) in JSON format. Available only under the `metadata` feature. /// /// Functions from the following sources are included: /// 1) Functions defined in an [`AST`][crate::AST] @@ -244,11 +233,9 @@ impl Engine { .map(|f| f.into()) .for_each(|info| global.functions.push(info)); - if let Some(ast) = ast { - ast.iter_functions() - .map(|f| f.into()) - .for_each(|info| global.functions.push(info)); - } + ast.iter_functions() + .map(|f| f.into()) + .for_each(|info| global.functions.push(info)); global.functions.sort();