summaryrefslogtreecommitdiffstats
path: root/third_party/rust/uniffi_meta/src/types.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--third_party/rust/uniffi_meta/src/types.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/third_party/rust/uniffi_meta/src/types.rs b/third_party/rust/uniffi_meta/src/types.rs
index 24f8a6f2a8..51bf156b50 100644
--- a/third_party/rust/uniffi_meta/src/types.rs
+++ b/third_party/rust/uniffi_meta/src/types.rs
@@ -21,8 +21,12 @@ use crate::Checksum;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Checksum, Ord, PartialOrd)]
pub enum ObjectImpl {
+ // A single Rust type
Struct,
+ // A trait that's can be implemented by Rust types
Trait,
+ // A trait + a callback interface -- can be implemented by both Rust and foreign types.
+ CallbackTrait,
}
impl ObjectImpl {
@@ -31,27 +35,26 @@ impl ObjectImpl {
/// Includes `r#`, traits get a leading `dyn`. If we ever supported associated types, then
/// this would also include them.
pub fn rust_name_for(&self, name: &str) -> String {
- if self == &ObjectImpl::Trait {
+ if self.is_trait_interface() {
format!("dyn r#{name}")
} else {
format!("r#{name}")
}
}
- // uniffi_meta and procmacro support tend to carry around `is_trait` bools. This makes that
- // mildly less painful
- pub fn from_is_trait(is_trait: bool) -> Self {
- if is_trait {
- ObjectImpl::Trait
- } else {
- ObjectImpl::Struct
- }
+ pub fn is_trait_interface(&self) -> bool {
+ matches!(self, Self::Trait | Self::CallbackTrait)
+ }
+
+ pub fn has_callback_interface(&self) -> bool {
+ matches!(self, Self::CallbackTrait)
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Checksum, Ord, PartialOrd)]
pub enum ExternalKind {
Interface,
+ Trait,
// Either a record or enum
DataClass,
}
@@ -85,7 +88,6 @@ pub enum Type {
// How the object is implemented.
imp: ObjectImpl,
},
- ForeignExecutor,
// Types defined in the component API, each of which has a string name.
Record {
module_path: String,