fn add_metadata_from_udl()

in uniffi_bindgen/src/pipeline/initial/mod.rs [84:138]


    fn add_metadata_from_udl(
        metadata_converter: &mut UniffiMetaConverter,
        config_supplier: &impl BindgenCrateConfigSupplier,
        udl: &str,
        crate_name: &str,
        library_mode: bool,
    ) -> Result<()> {
        let metadata_group = uniffi_udl::parse_udl(udl, crate_name)?;
        // parse_udl returns a metadata group, which is nice for the CI, but we actually want to
        // start with a raw metadata list
        if let Some(docstring) = metadata_group.namespace_docstring {
            metadata_converter
                .add_module_docstring(metadata_group.namespace.name.clone(), docstring);
        }
        if !library_mode {
            if let Some(path) = config_supplier.get_toml_path(&metadata_group.namespace.crate_name)
            {
                metadata_converter
                    .add_module_config_toml(metadata_group.namespace.name.clone(), &path)?;
            }
        }
        metadata_converter
            .add_metadata_item(uniffi_meta::Metadata::Namespace(metadata_group.namespace))?;
        for mut meta in metadata_group.items {
            // some items are both in UDL and library metadata. For many that's fine but
            // uniffi-traits aren't trivial to compare meaning we end up with dupes.
            // We filter out such problematic items here.
            if library_mode && matches!(meta, uniffi_meta::Metadata::UniffiTrait { .. }) {
                continue;
            }
            // Make sure metadata checksums are set
            match &mut meta {
                uniffi_meta::Metadata::Func(func) => {
                    func.checksum = Some(uniffi_meta::checksum(&interface::Function::from(
                        func.clone(),
                    )));
                }
                uniffi_meta::Metadata::Method(meth) => {
                    meth.checksum = Some(uniffi_meta::checksum(&interface::Method::from(
                        meth.clone(),
                    )));
                }
                uniffi_meta::Metadata::Constructor(cons) => {
                    cons.checksum = Some(uniffi_meta::checksum(&interface::Constructor::from(
                        cons.clone(),
                    )));
                }
                // Note: UDL-based callbacks don't have checksum functions, don't set the
                // checksum for those.
                _ => (),
            }
            metadata_converter.add_metadata_item(meta)?;
        }
        Ok(())
    }