From 01149c8d459c7ff4dbca8a39ab7dfb2b1f91b8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 16 Feb 2021 15:13:31 +0100 Subject: [PATCH] rust: Clean up our deps --- rust-sdk/Cargo.toml | 18 ++++++++--------- rust-sdk/src/machine.rs | 44 ++++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/rust-sdk/Cargo.toml b/rust-sdk/Cargo.toml index ce3afcd490..25030e115b 100644 --- a/rust-sdk/Cargo.toml +++ b/rust-sdk/Cargo.toml @@ -10,30 +10,28 @@ name = "matrix_crypto" [dependencies] matrix-sdk-common = { git = "https://github.com/matrix-org/matrix-rust-sdk/"} -futures = { version = "0.3.12", default_features = false, features = ["executor"] } -tokio = { version = "1.2.0", default_features = false, features = ["rt-multi-thread", "time"] } + serde_json = "1.0.62" -thiserror = "1.0.23" http = "0.2.3" + +thiserror = "1.0.23" tracing = "0.1.23" tracing-subscriber = "0.2.15" -once_cell = "1.5.2" [dependencies.matrix-sdk-crypto] git = "https://github.com/matrix-org/matrix-rust-sdk/" features = ["sled_cryptostore"] +[dependencies.tokio] +version = "1.2.0" +default_features = false +features = ["rt-multi-thread"] + [dependencies.uniffi] version = "0.7.0" git = "https://github.com/mozilla/uniffi-rs" branch = "tagged-unions" -[dependencies.ruma] -version = "0.0.2" -git = "https://github.com/ruma/ruma" -rev = "d6aa37c848b7f682a98c25b346899e284ffc6df7" -features = ["client-api", "compat", "unstable-pre-spec", "unstable-exhaustive-types"] - [build-dependencies] uniffi_build = "0.7.0" diff --git a/rust-sdk/src/machine.rs b/rust-sdk/src/machine.rs index 7f96f61ae6..e1a9d01b8c 100644 --- a/rust-sdk/src/machine.rs +++ b/rust-sdk/src/machine.rs @@ -1,13 +1,11 @@ use std::{ collections::{BTreeMap, HashMap}, convert::TryFrom, - time::Duration, }; -use futures::executor::block_on; use http::Response; use serde_json::json; -use tokio::{runtime::Runtime, time::sleep}; +use tokio::runtime::Runtime; use matrix_sdk_common::{ api::r0::{ @@ -17,6 +15,7 @@ use matrix_sdk_common::{ }, sync::sync_events::{DeviceLists as RumaDeviceLists, ToDevice}, }, + assign, identifiers::{DeviceKeyAlgorithm, UserId}, uuid::Uuid, UInt, @@ -40,7 +39,7 @@ pub struct DeviceLists { impl Into for DeviceLists { fn into(self) -> RumaDeviceLists { - RumaDeviceLists { + assign!(RumaDeviceLists::new(), { changed: self .changed .into_iter() @@ -51,7 +50,7 @@ impl Into for DeviceLists { .into_iter() .filter_map(|u| UserId::try_from(u).ok()) .collect(), - } + }) } } @@ -188,12 +187,13 @@ impl OlmMachine { pub fn new(user_id: &str, device_id: &str, path: &str) -> Result { let user_id = UserId::try_from(user_id)?; let device_id = device_id.into(); + let runtime = Runtime::new().unwrap(); Ok(OlmMachine { - inner: block_on(InnerMachine::new_with_default_store( + inner: runtime.block_on(InnerMachine::new_with_default_store( &user_id, device_id, path, None, ))?, - runtime: Runtime::new().unwrap(), + runtime, }) } @@ -208,7 +208,8 @@ impl OlmMachine { pub fn get_device(&self, user_id: &str, device_id: &str) -> Option { let user_id = UserId::try_from(user_id).unwrap(); - block_on(self.inner.get_device(&user_id, device_id.into())) + self.runtime + .block_on(self.inner.get_device(&user_id, device_id.into())) .unwrap() .map(|d| Device { user_id: d.user_id().to_string(), @@ -223,7 +224,8 @@ impl OlmMachine { pub fn get_user_devices(&self, user_id: &str) -> Vec { let user_id = UserId::try_from(user_id).unwrap(); - block_on(self.inner.get_user_devices(&user_id)) + self.runtime + .block_on(self.inner.get_user_devices(&user_id)) .unwrap() .devices() .map(|d| Device { @@ -263,7 +265,8 @@ impl OlmMachine { } .expect("Can't convert json string to response"); - block_on(self.inner.mark_request_as_sent(&id, &response))?; + self.runtime + .block_on(self.inner.mark_request_as_sent(&id, &response))?; Ok(()) } @@ -271,9 +274,12 @@ impl OlmMachine { pub fn start_verification(&self, device: &Device) -> Result { let user_id = UserId::try_from(device.user_id.clone()).unwrap(); let device_id = device.device_id.as_str().into(); - let device = block_on(self.inner.get_device(&user_id, device_id))?.unwrap(); + let device = self + .runtime + .block_on(self.inner.get_device(&user_id, device_id))? + .unwrap(); - let (sas, request) = block_on(device.start_verification())?; + let (sas, request) = self.runtime.block_on(device.start_verification())?; Ok(Sas { other_user_id: sas.other_user_id().to_string(), @@ -284,7 +290,8 @@ impl OlmMachine { } pub fn outgoing_requests(&self) -> Vec { - block_on(self.inner.outgoing_requests()) + self.runtime + .block_on(self.inner.outgoing_requests()) .into_iter() .map(|r| r.into()) .collect() @@ -303,10 +310,11 @@ impl OlmMachine { .map(|(k, v)| (DeviceKeyAlgorithm::from(k), v.into())) .collect(); - block_on( - self.inner - .receive_sync_changes(&events, &device_changes, &key_counts), - ) - .unwrap(); + self.runtime + .block_on( + self.inner + .receive_sync_changes(&events, &device_changes, &key_counts), + ) + .unwrap(); } }