Skip to content

Commit

Permalink
Allow external languages to implement callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tomleavy committed Feb 26, 2024
1 parent 51f274c commit 659ed06
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions mls-rs-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ crate-type = ["lib", "cdylib"]
name = "mls_rs_uniffi"

[dependencies]
async-trait = "0.1.77"
maybe-async = "0.2.10"
mls-rs = { path = "../mls-rs" }
mls-rs-core = { path = "../mls-rs-core" }
Expand Down
14 changes: 7 additions & 7 deletions mls-rs-uniffi/src/config/group_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ impl mls_rs_core::group::EpochRecord for EpochRecord {

#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)]
#[cfg_attr(mls_build_async, maybe_async::must_be_async)]
#[uniffi::export]
#[uniffi::export(with_foreign)]
pub trait GroupStateStorage: Send + Sync + Debug {
async fn state(&self, group_id: &[u8]) -> Result<Option<Vec<u8>>, FFICallbackError>;
async fn state(&self, group_id: Vec<u8>) -> Result<Option<Vec<u8>>, FFICallbackError>;
async fn epoch(
&self,
group_id: &[u8],
group_id: Vec<u8>,
epoch_id: u64,
) -> Result<Option<Vec<u8>>, FFICallbackError>;

Expand All @@ -46,7 +46,7 @@ pub trait GroupStateStorage: Send + Sync + Debug {
epoch_updates: Vec<Arc<EpochRecord>>,
) -> Result<(), FFICallbackError>;

async fn max_epoch_id(&self, group_id: &[u8]) -> Result<Option<u64>, FFICallbackError>;
async fn max_epoch_id(&self, group_id: Vec<u8>) -> Result<Option<u64>, FFICallbackError>;
}

#[derive(Debug, Clone)]
Expand All @@ -67,7 +67,7 @@ impl mls_rs_core::group::GroupStateStorage for GroupStateStorageWrapper {
where
T: mls_rs_core::group::GroupState + MlsEncode + MlsDecode,
{
let state_data = self.0.state(group_id)?;
let state_data = self.0.state(group_id.to_vec())?;

state_data
.as_deref()
Expand All @@ -80,7 +80,7 @@ impl mls_rs_core::group::GroupStateStorage for GroupStateStorageWrapper {
where
T: mls_rs_core::group::EpochRecord + MlsEncode + MlsDecode,
{
let epoch_data = self.0.epoch(group_id, epoch_id)?;
let epoch_data = self.0.epoch(group_id.to_vec(), epoch_id)?;

epoch_data
.as_deref()
Expand Down Expand Up @@ -118,6 +118,6 @@ impl mls_rs_core::group::GroupStateStorage for GroupStateStorageWrapper {
}

async fn max_epoch_id(&self, group_id: &[u8]) -> Result<Option<u64>, Self::Error> {
self.0.max_epoch_id(group_id)
self.0.max_epoch_id(group_id.to_vec())
}
}
2 changes: 1 addition & 1 deletion mls-rs-uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
//!
//! [UniFFI]: https://mozilla.github.io/uniffi-rs/

mod config;
#[cfg(test)]
pub mod test_utils;
mod config;

use std::sync::Arc;

Expand Down

0 comments on commit 659ed06

Please sign in to comment.