Skip to content

Commit c7633cc

Browse files
committed
Allow external languages to implement callbacks
1 parent 51f274c commit c7633cc

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

mls-rs-uniffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ crate-type = ["lib", "cdylib"]
1515
name = "mls_rs_uniffi"
1616

1717
[dependencies]
18+
async-trait = "0.1.77"
1819
maybe-async = "0.2.10"
1920
mls-rs = { path = "../mls-rs" }
2021
mls-rs-core = { path = "../mls-rs-core" }

mls-rs-uniffi/src/config/group_state.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ impl mls_rs_core::group::EpochRecord for EpochRecord {
3030

3131
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)]
3232
#[cfg_attr(mls_build_async, maybe_async::must_be_async)]
33-
#[uniffi::export]
33+
#[uniffi::export(with_foreign)]
3434
pub trait GroupStateStorage: Send + Sync + Debug {
35-
async fn state(&self, group_id: &[u8]) -> Result<Option<Vec<u8>>, FFICallbackError>;
35+
async fn state(&self, group_id: Vec<u8>) -> Result<Option<Vec<u8>>, FFICallbackError>;
3636
async fn epoch(
3737
&self,
38-
group_id: &[u8],
38+
group_id: Vec<u8>,
3939
epoch_id: u64,
4040
) -> Result<Option<Vec<u8>>, FFICallbackError>;
4141

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

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

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

7272
state_data
7373
.as_deref()
@@ -80,7 +80,7 @@ impl mls_rs_core::group::GroupStateStorage for GroupStateStorageWrapper {
8080
where
8181
T: mls_rs_core::group::EpochRecord + MlsEncode + MlsDecode,
8282
{
83-
let epoch_data = self.0.epoch(group_id, epoch_id)?;
83+
let epoch_data = self.0.epoch(group_id.to_vec(), epoch_id)?;
8484

8585
epoch_data
8686
.as_deref()
@@ -118,6 +118,6 @@ impl mls_rs_core::group::GroupStateStorage for GroupStateStorageWrapper {
118118
}
119119

120120
async fn max_epoch_id(&self, group_id: &[u8]) -> Result<Option<u64>, Self::Error> {
121-
self.0.max_epoch_id(group_id)
121+
self.0.max_epoch_id(group_id.to_vec())
122122
}
123123
}

0 commit comments

Comments
 (0)