Use Box<[]>.
This commit is contained in:
parent
bffc73435c
commit
a9aa8e84fd
@ -72,7 +72,7 @@ pub struct ScriptFnDef {
|
||||
/// Not available under `no_function`.
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(feature = "metadata")]
|
||||
pub comments: StaticVec<Box<str>>,
|
||||
pub comments: Option<Box<[Box<str>]>>,
|
||||
}
|
||||
|
||||
impl fmt::Display for ScriptFnDef {
|
||||
@ -151,7 +151,10 @@ impl<'a> From<&'a ScriptFnDef> for ScriptFnMetadata<'a> {
|
||||
Self {
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(feature = "metadata")]
|
||||
comments: value.comments.iter().map(Box::as_ref).collect(),
|
||||
comments: value
|
||||
.comments
|
||||
.as_ref()
|
||||
.map_or_else(|| Vec::new(), |v| v.iter().map(Box::as_ref).collect()),
|
||||
access: value.access,
|
||||
name: &value.name,
|
||||
params: value.params.iter().map(|s| s.as_str()).collect(),
|
||||
|
@ -1165,7 +1165,7 @@ pub fn optimize_into_ast(
|
||||
mods: crate::engine::Imports::new(),
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(feature = "metadata")]
|
||||
comments: StaticVec::new(),
|
||||
comments: None,
|
||||
})
|
||||
.for_each(|fn_def| {
|
||||
lib2.set_script_fn(fn_def);
|
||||
|
12
src/parse.rs
12
src/parse.rs
@ -2733,7 +2733,7 @@ fn parse_stmt(
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(feature = "metadata")]
|
||||
let comments = {
|
||||
let mut comments = StaticVec::<Box<str>>::new();
|
||||
let mut comments = Vec::<Box<str>>::new();
|
||||
let mut comments_pos = Position::NONE;
|
||||
|
||||
// Handle doc-comments.
|
||||
@ -2996,7 +2996,7 @@ fn parse_fn(
|
||||
settings: ParseSettings,
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(feature = "metadata")]
|
||||
comments: StaticVec<Box<str>>,
|
||||
comments: Vec<Box<str>>,
|
||||
) -> Result<ScriptFnDef, ParseError> {
|
||||
let mut settings = settings;
|
||||
|
||||
@ -3078,7 +3078,11 @@ fn parse_fn(
|
||||
mods: crate::engine::Imports::new(),
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(feature = "metadata")]
|
||||
comments,
|
||||
comments: if comments.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(comments.into())
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@ -3223,7 +3227,7 @@ fn parse_anon_fn(
|
||||
mods: crate::engine::Imports::new(),
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(feature = "metadata")]
|
||||
comments: StaticVec::new(),
|
||||
comments: None,
|
||||
};
|
||||
|
||||
let fn_ptr = crate::FnPtr::new_unchecked(fn_name, StaticVec::new());
|
||||
|
@ -165,7 +165,8 @@ impl From<&crate::module::FuncInfo> for FnMetadata {
|
||||
.get_script_fn_def()
|
||||
.expect("scripted function")
|
||||
.comments
|
||||
.to_vec()
|
||||
.as_ref()
|
||||
.map_or_else(|| Vec::new(), |v| v.to_vec())
|
||||
}
|
||||
} else {
|
||||
Vec::new()
|
||||
|
Loading…
Reference in New Issue
Block a user