use crate::core::ir::MethodDef;
use super::excluded::substitute_excluded_carriers_in_rust_type;
use crate::backends::dart::gen_rust_crate::conversions::frb_rust_type_excluded_aware;
pub(super) fn dart_fn_future_callback_type(
method: &MethodDef,
source_crate_name: &str,
_type_paths: &std::collections::HashMap<String, String>,
excluded_type_paths: &std::collections::HashMap<String, String>,
) -> String {
let (params_str, dart_fn_ret) = dart_fn_future_params_and_ret(method, source_crate_name, excluded_type_paths);
format!("Box<dyn Fn({params_str}) -> {dart_fn_ret} + Send + Sync>")
}
pub(super) fn dart_fn_future_factory_param_type(
method: &MethodDef,
source_crate_name: &str,
_type_paths: &std::collections::HashMap<String, String>,
excluded_type_paths: &std::collections::HashMap<String, String>,
) -> String {
let (params_str, dart_fn_ret) = dart_fn_future_params_and_ret(method, source_crate_name, excluded_type_paths);
format!("impl Fn({params_str}) -> {dart_fn_ret} + Send + Sync + 'static")
}
fn dart_fn_future_params_and_ret(
method: &MethodDef,
source_crate_name: &str,
excluded_type_paths: &std::collections::HashMap<String, String>,
) -> (String, String) {
let params: Vec<String> = method
.params
.iter()
.map(|p| {
let ty = frb_rust_type_excluded_aware(&p.ty, p.optional, excluded_type_paths);
substitute_excluded_carriers_in_rust_type(&ty, source_crate_name, excluded_type_paths)
})
.collect();
let ret = frb_rust_type_excluded_aware(&method.return_type, false, excluded_type_paths);
let ret_substituted = substitute_excluded_carriers_in_rust_type(&ret, source_crate_name, excluded_type_paths);
let dart_fn_ret = format!("DartFnFuture<{ret_substituted}>");
(params.join(", "), dart_fn_ret)
}