in uniffi_udl/src/finder.rs [139:197]
fn add_type_definitions_to(&self, types: &mut TypeCollector) -> Result<()> {
let attrs = TypedefAttributes::try_from(self.attributes.as_ref())?;
let ty = if attrs.is_custom() {
// A type which wraps a builtin with an `FfiConverter` implementation.
// If local we will generate that implementation, if external we will reference it.
let builtin = types.resolve_type_expression(&self.type_)?;
let module_path = attrs
.get_crate_name()
.unwrap_or_else(|| types.module_path());
Type::Custom {
module_path,
name: self.identifier.0.to_string(),
builtin: builtin.into(),
}
} else {
let typedef_type = match &self.type_.type_ {
weedle::types::Type::Single(weedle::types::SingleType::NonAny(
weedle::types::NonAnyType::Identifier(weedle::types::MayBeNull {
type_: i,
..
}),
)) => i.0,
_ => bail!("Failed to get typedef type: {:?}", self),
};
let name = self.identifier.0.to_string();
let module_path = attrs
.get_crate_name()
.unwrap_or_else(|| types.module_path());
match typedef_type {
"dictionary" | "record" | "struct" => Type::Record {
module_path,
name,
},
"enum" => Type::Enum {
module_path,
name,
},
"interface" | "impl" => Type::Object {
module_path,
name,
imp: ObjectImpl::Struct,
},
"trait" => Type::Object {
module_path,
name,
imp: ObjectImpl::Trait,
},
"callback" | "trait_with_foreign" => Type::Object {
module_path,
name,
imp: ObjectImpl::CallbackTrait,
},
// "extern" gets a special error to help upgrading
"extern" => bail!(ERR_TYPEDEF_EXTERN),
_ => bail!("Can't work out the type - no attributes and unknown extern type '{typedef_type}'"),
}
};
types.add_type_definition(self.identifier.0, ty)
}