Skip to content

Commit

Permalink
Add Callable::ffi_func
Browse files Browse the repository at this point in the history
All the callable types implement this, so let's add it to the trait.  I
want to use this eventually for the Gecko JS bindings.
  • Loading branch information
bendk committed Oct 31, 2024
1 parent 279a587 commit 231bf9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions uniffi_bindgen/src/interface/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ pub trait Callable {
}
}

// Scaffolding function
fn ffi_func(&self) -> &FfiFunction;

// Quick way to get the rust future scaffolding function that corresponds to our return type.

fn ffi_rust_future_poll(&self, ci: &ComponentInterface) -> String {
Expand Down Expand Up @@ -312,6 +315,10 @@ impl Callable for Function {
fn is_async(&self) -> bool {
self.is_async
}

fn ffi_func(&self) -> &FfiFunction {
&self.ffi_func
}
}

// Needed because Rinja likes to add extra refs to variables
Expand All @@ -332,6 +339,10 @@ impl<T: Callable> Callable for &T {
(*self).is_async()
}

fn ffi_func(&self) -> &FfiFunction {
(*self).ffi_func()
}

fn takes_self(&self) -> bool {
(*self).takes_self()
}
Expand Down
8 changes: 8 additions & 0 deletions uniffi_bindgen/src/interface/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,10 @@ impl Callable for Constructor {
fn is_async(&self) -> bool {
self.is_async
}

fn ffi_func(&self) -> &FfiFunction {
&self.ffi_func
}
}

impl Callable for Method {
Expand All @@ -751,6 +755,10 @@ impl Callable for Method {
fn takes_self(&self) -> bool {
true
}

fn ffi_func(&self) -> &FfiFunction {
&self.ffi_func
}
}

#[cfg(test)]
Expand Down

0 comments on commit 231bf9a

Please sign in to comment.