use super::rust_buffer;
use super::*;
pub fn map_namespace(namespace: initial::Namespace, context: &Context) -> Result<Namespace> {
let mut child_context = context.clone();
let context = &mut child_context;
context.update_from_namespace(&namespace)?;
Ok(Namespace {
ffi_definitions: IndexSet::from_iter(sort::sort_ffi_definitions(
[
rust_buffer::ffi_definitions(context)?,
checksums::ffi_definitions(&namespace)?,
ffi_functions::ffi_definitions(&namespace, context)?,
objects::ffi_definitions(&namespace, context)?,
callback_interfaces::ffi_definitions(&namespace, context)?,
rust_future::ffi_definitions(&namespace)?,
]
.into_iter()
.flatten(),
)),
checksums: checksums::checksums(&namespace)?,
type_definitions: {
let mut type_defs: Vec<TypeDefinition> = [
namespace
.type_definitions
.clone()
.into_iter()
.filter_map(|type_def| {
match exclude::should_exclude_toplevel_item(type_def.name(), context) {
Err(e) => Some(Err(e)),
Ok(true) => None,
Ok(false) => Some(type_def.map_node(context)),
}
})
.collect::<Result<Vec<_>>>()?,
type_definitions_from_api::type_definitions(&namespace, context)?,
]
.into_iter()
.flatten()
.collect();
infer_recursive_enums::infer_recursive_types(&mut type_defs);
sort::sort_type_definitions(type_defs)
},
ffi_rustbuffer_alloc: rust_buffer::rustbuffer_alloc_fn_name(context)?,
ffi_rustbuffer_from_bytes: rust_buffer::rustbuffer_from_bytes_fn_name(context)?,
ffi_rustbuffer_free: rust_buffer::rustbuffer_free_fn_name(context)?,
ffi_rustbuffer_reserve: rust_buffer::rustbuffer_reserve_fn_name(context)?,
ffi_uniffi_contract_version: checksums::ffi_uniffi_contract_version(&namespace),
correct_contract_version: uniffi_meta::UNIFFI_CONTRACT_VERSION.to_string(),
crate_name: namespace.crate_name,
config_toml: namespace.config_toml,
docstring: namespace.docstring,
functions: namespace
.functions
.into_iter()
.filter_map(
|f| match exclude::should_exclude_toplevel_item(&f.name, context) {
Err(e) => Some(Err(e)),
Ok(true) => None,
Ok(false) => Some(f.map_node(context)),
},
)
.collect::<Result<Vec<_>>>()?,
name: namespace.name,
})
}