Use Box<str> internally.

This commit is contained in:
Stephen Chung
2021-11-11 13:55:52 +08:00
parent 6b27ca19d5
commit 0fbc437916
9 changed files with 121 additions and 97 deletions

View File

@@ -46,9 +46,9 @@ impl From<crate::FnAccess> for FnAccess {
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct FnParam {
pub name: String,
pub name: Box<str>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub typ: Option<String>,
pub typ: Option<Box<str>>,
}
impl PartialOrd for FnParam {
@@ -98,10 +98,10 @@ struct FnMetadata {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub params: Vec<FnParam>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub return_type: Option<String>,
pub return_type: Option<Box<str>>,
pub signature: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub doc_comments: Vec<String>,
pub doc_comments: Vec<Box<str>>,
}
impl PartialOrd for FnMetadata {
@@ -142,17 +142,17 @@ impl From<&crate::module::FuncInfo> for FnMetadata {
let mut seg = s.splitn(2, ':');
let name = seg
.next()
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "_".to_string());
let typ = seg.next().map(|s| s.trim().to_string());
.map(|s| s.trim().into())
.unwrap_or_else(|| "_".into());
let typ = seg.next().map(|s| s.trim().into());
FnParam { name, typ }
})
.collect(),
return_type: info
.param_names
.last()
.map(|s| s.to_string())
.or_else(|| Some("()".to_string())),
.map(|s| s.as_str().into())
.or_else(|| Some("()".into())),
signature: info.gen_signature(),
doc_comments: if info.func.is_script() {
#[cfg(feature = "no_function")]
@@ -186,14 +186,14 @@ impl From<crate::ast::ScriptFnMetadata<'_>> for FnMetadata {
params: info
.params
.iter()
.map(|s| FnParam {
name: s.to_string(),
typ: Some("Dynamic".to_string()),
.map(|&s| FnParam {
name: s.into(),
typ: Some("Dynamic".into()),
})
.collect(),
return_type: Some("Dynamic".to_string()),
return_type: Some("Dynamic".into()),
signature: info.to_string(),
doc_comments: info.comments.iter().map(|s| s.to_string()).collect(),
doc_comments: info.comments.iter().map(|&s| s.into()).collect(),
}
}
}