use uniffi_bindgen::interface::{DefaultValue, Literal, Type};
pub(super) const LOCAL_CRATE_SENTINEL: &str = "crate_name";
#[derive(Debug)]
pub(super) struct FnDef {
pub name: String,
pub args: Vec<ArgDef>,
pub return_type: Option<Type>,
pub throws_type: Option<Type>,
pub is_async: bool,
pub docstring: Option<String>,
}
#[derive(Debug)]
pub(super) struct ArgDef {
pub name: String,
pub type_: Type,
pub default: Option<DefaultValue>,
}
#[derive(Debug)]
pub(super) struct FieldDef {
pub name: String,
pub type_: Type,
pub docstring: Option<String>,
pub default: Option<DefaultValue>,
}
#[derive(Debug)]
pub(super) struct VariantDef {
pub name: String,
pub fields: Vec<FieldDef>,
pub docstring: Option<String>,
pub discr: Option<Literal>,
}
#[derive(Debug)]
pub(super) struct ErrorDef {
pub name: String,
pub variants: Vec<VariantDef>,
pub is_flat: bool,
pub is_non_exhaustive: bool,
pub docstring: Option<String>,
pub methods: Vec<MethodDef>,
pub constructors: Vec<CtorDef>,
}
#[derive(Debug)]
pub(super) struct EnumDef {
pub name: String,
pub variants: Vec<VariantDef>,
pub is_flat: bool,
pub is_non_exhaustive: bool,
pub docstring: Option<String>,
pub methods: Vec<MethodDef>,
pub constructors: Vec<CtorDef>,
pub traits: SynthesisedTraits,
}
#[derive(Debug, Default)]
pub(super) struct SynthesisedTraits {
pub display: Option<String>,
pub debug: Option<String>,
pub eq: Option<String>,
pub hash: Option<String>,
pub ord: Option<String>,
}
#[derive(Debug)]
pub(super) struct RecordDef {
pub name: String,
pub fields: Vec<FieldDef>,
pub docstring: Option<String>,
pub methods: Vec<MethodDef>,
pub constructors: Vec<CtorDef>,
pub traits: SynthesisedTraits,
}
#[derive(Debug)]
pub(super) struct CtorDef {
pub name: String,
pub args: Vec<ArgDef>,
pub throws_type: Option<Type>,
pub is_async: bool,
pub docstring: Option<String>,
}
#[derive(Debug)]
pub(super) struct MethodDef {
pub name: String,
pub args: Vec<ArgDef>,
pub return_type: Option<Type>,
pub throws_type: Option<Type>,
pub is_async: bool,
pub docstring: Option<String>,
}
#[derive(Debug)]
pub(super) struct ObjectDef {
pub name: String,
pub constructors: Vec<CtorDef>,
pub methods: Vec<MethodDef>,
pub docstring: Option<String>,
pub is_error: bool,
pub is_trait: bool,
pub traits: SynthesisedTraits,
}
#[derive(Debug)]
pub(super) struct CustomTypeDef {
pub name: String,
pub builtin: Type,
pub module_path: String,
}
#[derive(Debug)]
pub(super) struct CallbackMethodDef {
pub name: String,
pub args: Vec<ArgDef>,
pub return_type: Option<Type>,
pub is_async: bool,
pub docstring: Option<String>,
}
#[derive(Debug)]
pub(super) struct CallbackInterfaceDef {
pub name: String,
pub methods: Vec<CallbackMethodDef>,
pub docstring: Option<String>,
}
#[derive(Debug)]
pub(super) struct BindingsMetadata {
pub namespace: String,
pub namespace_docstring: Option<String>,
pub local_crate: String,
pub ffi_namespace: String,
pub functions: Vec<FnDef>,
pub errors: Vec<ErrorDef>,
pub enums: Vec<EnumDef>,
pub records: Vec<RecordDef>,
pub objects: Vec<ObjectDef>,
pub custom_types: Vec<CustomTypeDef>,
pub callback_interfaces: Vec<CallbackInterfaceDef>,
}
impl Default for BindingsMetadata {
fn default() -> Self {
Self {
namespace: String::new(),
namespace_docstring: None,
local_crate: LOCAL_CRATE_SENTINEL.to_string(),
ffi_namespace: LOCAL_CRATE_SENTINEL.to_string(),
functions: Vec::new(),
errors: Vec::new(),
enums: Vec::new(),
records: Vec::new(),
objects: Vec::new(),
custom_types: Vec::new(),
callback_interfaces: Vec::new(),
}
}
}