-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1573 from bendk/proc-macro-callbacks
Proc macro callbacks
- Loading branch information
Showing
54 changed files
with
1,399 additions
and
598 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
use crate::BasicError; | ||
|
||
#[uniffi::export(callback_interface)] | ||
pub trait TestCallbackInterface { | ||
fn do_nothing(&self); | ||
fn add(&self, a: u32, b: u32) -> u32; | ||
fn try_parse_int(&self, value: String) -> Result<u32, BasicError>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
//! Backend-agnostic askama filters | ||
use crate::interface::{CallbackInterface, ComponentInterface, Enum, Function, Object, Record}; | ||
use askama::Result; | ||
use std::fmt; | ||
|
||
// Need to define an error that implements std::error::Error, which neither String nor | ||
// anyhow::Error do. | ||
#[derive(Debug)] | ||
struct UniFFIError { | ||
message: String, | ||
} | ||
|
||
impl UniFFIError { | ||
fn new(message: String) -> Self { | ||
Self { message } | ||
} | ||
} | ||
|
||
impl fmt::Display for UniFFIError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{}", self.message) | ||
} | ||
} | ||
|
||
impl std::error::Error for UniFFIError {} | ||
|
||
macro_rules! lookup_error { | ||
($($args:tt)*) => { | ||
askama::Error::Custom(Box::new(UniFFIError::new(format!($($args)*)))) | ||
} | ||
} | ||
|
||
/// Get an Enum definition by name | ||
pub fn get_enum_definition<'a>(ci: &'a ComponentInterface, name: &str) -> Result<&'a Enum> { | ||
ci.get_enum_definition(name) | ||
.ok_or_else(|| lookup_error!("enum {name} not found")) | ||
} | ||
|
||
/// Get a Record definition by name | ||
pub fn get_record_definition<'a>(ci: &'a ComponentInterface, name: &str) -> Result<&'a Record> { | ||
ci.get_record_definition(name) | ||
.ok_or_else(|| lookup_error!("record {name} not found")) | ||
} | ||
|
||
/// Get a Function definition by name | ||
pub fn get_function_definition<'a>(ci: &'a ComponentInterface, name: &str) -> Result<&'a Function> { | ||
ci.get_function_definition(name) | ||
.ok_or_else(|| lookup_error!("function {name} not found")) | ||
} | ||
|
||
/// Get an Object definition by name | ||
pub fn get_object_definition<'a>(ci: &'a ComponentInterface, name: &str) -> Result<&'a Object> { | ||
ci.get_object_definition(name) | ||
.ok_or_else(|| lookup_error!("object {name} not found")) | ||
} | ||
|
||
/// Get an Callback Interface definition by name | ||
pub fn get_callback_interface_definition<'a>( | ||
ci: &'a ComponentInterface, | ||
name: &str, | ||
) -> Result<&'a CallbackInterface> { | ||
ci.get_callback_interface_definition(name) | ||
.ok_or_else(|| lookup_error!("callback interface {name} not found")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
uniffi_bindgen/src/bindings/kotlin/templates/CallbackInterfaceTemplate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.