fix clippy and globalref and android

This commit is contained in:
John Smith
2022-03-13 12:45:36 -04:00
parent f7f4d86cf1
commit 2cdfa59bb6
13 changed files with 97 additions and 107 deletions

View File

@@ -19,6 +19,13 @@ pub struct AndroidGlobals {
pub ctx: GlobalRef,
}
impl Drop for AndroidGlobals {
fn drop(&mut self) {
// Ensure we're attached before dropping GlobalRef
self.vm.attach_current_thread_as_daemon().unwrap();
}
}
lazy_static! {
pub static ref ANDROID_GLOBALS: Arc<Mutex<Option<AndroidGlobals>>> = Arc::new(Mutex::new(None));
}
@@ -76,7 +83,7 @@ pub fn veilid_core_setup_android<'a>(
pub fn get_android_globals() -> (JavaVM, GlobalRef) {
let globals_locked = ANDROID_GLOBALS.lock();
let globals = globals_locked.as_ref().unwrap();
let env = globals.vm.attach_current_thread().unwrap();
let env = globals.vm.attach_current_thread_as_daemon().unwrap();
let vm = env.get_java_vm().unwrap();
let ctx = globals.ctx.clone();
(vm, ctx)

View File

@@ -1455,9 +1455,9 @@ impl RPCProcessor {
match eventual_value.await {
ReceiptEvent::Returned => Ok(true),
ReceiptEvent::Expired => Ok(false),
ReceiptEvent::Cancelled => Err(rpc_error_internal(
"receipt was dropped before expiration".to_owned(),
)),
ReceiptEvent::Cancelled => {
Err(rpc_error_internal("receipt was dropped before expiration"))
}
}
}

View File

@@ -279,13 +279,13 @@ async fn test_operations() {
assert_eq!(d1, d2);
assert!(d1 <= d2);
assert!(d1 >= d2);
assert!(!(d1 < d2));
assert!(!(d1 > d2));
assert!(d1 >= d2);
assert!(d1 <= d2);
assert_eq!(d2, d1);
assert!(d2 <= d1);
assert!(d2 >= d1);
assert!(!(d2 < d1));
assert!(!(d2 > d1));
assert!(d2 >= d1);
assert!(d2 <= d1);
// Verify nibbles
assert_eq!(d1.nibble(0), 0x9u8);

View File

@@ -83,21 +83,19 @@ cfg_if! {
else {
fn get_data_dir() -> PathBuf {
let out;
cfg_if! {
if #[cfg(target_os = "android")] {
out = PathBuf::from(intf::utils::android::get_files_dir());
PathBuf::from(intf::utils::android::get_files_dir())
} else {
use directories::*;
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "VeilidCoreTests") {
out = PathBuf::from(my_proj_dirs.data_local_dir());
PathBuf::from(my_proj_dirs.data_local_dir())
} else {
out = PathBuf::from("./");
PathBuf::from("./")
}
}
}
out
}
pub fn get_table_store_path() -> String {

View File

@@ -295,8 +295,8 @@ impl Address {
}
pub fn address_string_with_port(&self, port: u16) -> String {
match self {
Address::IPV4(v4) => format!("{}:{}", v4.to_string(), port),
Address::IPV6(v6) => format!("[{}]:{}", v6.to_string(), port),
Address::IPV4(v4) => format!("{}:{}", v4, port),
Address::IPV6(v6) => format!("[{}]:{}", v6, port),
}
}
pub fn is_global(&self) -> bool {

View File

@@ -262,7 +262,7 @@ impl FromStr for SplitUrl {
return Err("Invalid scheme specified".to_owned());
}
let userinfo = {
if let Some((userinfo_str, after)) = rest.split_once("@") {
if let Some((userinfo_str, after)) = rest.split_once('@') {
rest = after;
Some(url_decode(userinfo_str)?)
} else {