diff --git a/src/api/type_names.rs b/src/api/type_names.rs index f7897bf0..dda879fc 100644 --- a/src/api/type_names.rs +++ b/src/api/type_names.rs @@ -108,11 +108,15 @@ fn map_std_type_name(name: &str, shorthands: bool) -> &str { /// Format a Rust type to be display-friendly. /// +/// * `rhai::` prefix is cleared. /// * `()` is cleared. +/// * `&mut` is cleared. /// * `INT` and `FLOAT` are expanded. /// * [`RhaiResult`][crate::RhaiResult] and [`RhaiResultOf`][crate::RhaiResultOf] are expanded. #[cfg(feature = "metadata")] pub fn format_type(typ: &str, is_return_type: bool) -> std::borrow::Cow { + const RESULT_TYPE: &str = "Result<"; + const ERROR_TYPE: &str = ",Box>"; const RHAI_RESULT_TYPE: &str = "RhaiResult"; const RHAI_RESULT_TYPE_EXPAND: &str = "Result>"; const RHAI_RESULT_OF_TYPE: &str = "RhaiResultOf<"; @@ -135,6 +139,10 @@ pub fn format_type(typ: &str, is_return_type: bool) -> std::borrow::Cow { } else { format!("&mut {r}").into() }; + } else if typ.contains(" ") { + let typ = typ.replace(" ", ""); + let r = format_type(&typ, is_return_type); + return r.into_owned().into(); } match typ { @@ -167,6 +175,12 @@ pub fn format_type(typ: &str, is_return_type: bool) -> std::borrow::Cow { .replace("{}", format_type(inner, false).trim()) .into() } + ty if ty.starts_with(RESULT_TYPE) && ty.ends_with(ERROR_TYPE) => { + let inner = &ty[RESULT_TYPE.len()..ty.len() - ERROR_TYPE.len()]; + RHAI_RESULT_OF_TYPE_EXPAND + .replace("{}", format_type(inner, false).trim()) + .into() + } ty => ty.into(), } }